From patchwork Sun Aug 6 03:36:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710884 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp827024rwb; Sat, 5 Aug 2023 20:42:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGK7EIG8iL2i+Foc+82wN+352KEgqqkfShrki90XdSVbwkB68LIzlo5t2OgtiXTslNEPqmr X-Received: by 2002:ac8:58cb:0:b0:40f:d021:b0cc with SMTP id u11-20020ac858cb000000b0040fd021b0ccmr9163825qta.22.1691293347048; Sat, 05 Aug 2023 20:42:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293347; cv=none; d=google.com; s=arc-20160816; b=vBd2zzvczoLceA+BlWx0m3TIzfUfLIr+Ax10JtUEXn8gFWFDTtTngqPlNkslx6Lvef 8HmXINgJvxQ/Y3S1UuUooTKXUCMbkv6k9hPBr13yF11w5pkl6z2zGdbFXtkyKJsciduR jNpdr0WV2YY9ZLWKW6CrLqTEejgEu9ahOYbCqwP4/LfhYrghdctYRfKbZge8otRvrIna BvudrEH9Xzob6bAQd/arnyde6hxPvKFWdZflhoAYL/tiaJDt1VZBD+Xyj2qlEFhEBcJo sl9LPOD1ejEpgnQHTlRIcY4hfzzYVdDaKJ2fNM/XhCA36peNwZUX875z2S5U6wRzljCP Bb7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jsOBWOFossCHszj7zLjYTuH7ZUTZ9Rn/iuADRRkhtM4=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=ZYmEfyiJlnDx1mWakeUb23ZrNEWs+tuete3Fynee/z/2jqwR71PlblAPs3Vh4UkvDr xeKGaebZZi9XgUMSZ9lPk2++LHCwVbgvhm47zwHQUINyZlmYWifESzo/mtouAfVLhG6g agNS2fNa2Iqiij1voaWzFhLwZG2TxhF2ts8Xnf+fMs4UIneiI+SZqGoSgSaudEvRelCX qMX1wc8s7T2kW1g4suuY3p6lx3SScRKTlzUmc3DkyLifTM92NICdy3zfv859YTr+yEkf YqpbyupQd6NEWz8nPKLOt+PJ0e0ezLv5+CCG7gyhZuV/ajL7d+NoxJ1uRClKk2DRC3FV fU1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=T4bIw9fD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c7-20020ac87dc7000000b0040fd26e82ebsi3265629qte.375.2023.08.05.20.42.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:42:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=T4bIw9fD; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUa2-0003bM-JY; Sat, 05 Aug 2023 23:37:22 -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 1qSUa0-0003ZH-8I for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:20 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUZy-0007Vj-DU for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:20 -0400 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-268b3ddc894so1826196a91.1 for ; Sat, 05 Aug 2023 20:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293037; x=1691897837; 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=T4bIw9fD15LKS8IexBua3eZvM+LY9cFpmyNIxEuywgC+i4SMsp57LlYHJAeE2qUuY2 IyLSeOfEfTEv7WxweZsMU1DNnBo71Bz+e+Z9Qm15Hw7RArLX+TzSpdrl8IkmL6JiyhsL Qum3jwLLWp8YU7u6xabL2rIMYiwpsXlVmZMOiK1NbEwobdCVP1Hs4FWSji+GtSRj6dQi /wlqNph1m/iIibr7R8H2mzEMFzaiSTWNWt4NCMuQPntkJmpWM7SWB/Ce72mzcS0S231z bvsoRAoFyVVq1motBEkTwMnRSn1jhSj3dclKTh51QxLy8bv+uN9kG2GHxbF9B2fyu72r JYFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293037; x=1691897837; 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=X/M3zCXba+bj8prgZekp9lIoNdAZkRtOZwPqiTBhzV4dsLGflwClWOOJXZnF+HwT9Z TROkUMk1bLGrf3gOiM0VdnEsnHlzjmZ9TTm8SnODvEr3igFOjATXb+EIaIyFDnhsO69O vpbZIy6PjDrdebgOQ0eRhoYIl4cAdRtEApYVaZD064v9jkYg0QEL/E0Mtjm2ta8CECel b6qXkgxkgJOmqgYu3O+8dbwLeYN/V+A2XqTAId3npyhaKclro3dnsv8QX+N9xKEOjc9G fkwOL5Kn/yVj2Fv/y4XYD42InAgdUheiXlmbHzM8DapWcDHq5886fM2+Fm3tkEzDLiwH XpVQ== X-Gm-Message-State: AOJu0YyMmoUXQ+7PjZUoecT5fmcYw4xTv3sgIjkY7erDXwctkrKCdCaM UOfkH2Qa23pkqNFVPqaKV7Aqhs0a8K7bvBBKPE4= X-Received: by 2002:a17:90a:38e2:b0:268:557e:1848 with SMTP id x89-20020a17090a38e200b00268557e1848mr4245970pjb.2.1691293036982; Sat, 05 Aug 2023 20:37:16 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 01/24] accel/tcg: Adjust parameters and locking with do_{ld, st}_mmio_* Date: Sat, 5 Aug 2023 20:36:52 -0700 Message-Id: <20230806033715.244648-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Replace MMULookupPageData* with CPUTLBEntryFull, addr, size. Move QEMU_IOTHREAD_LOCK_GUARD to the caller. This simplifies the usage from do_ld16_beN and do_st16_leN, where we weren't locking the entire operation, and required hoop jumping for passing addr and size. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 67 +++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index ba44501a7c..23386ecfde 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -2066,24 +2066,22 @@ static void *atomic_mmu_lookup(CPUArchState *env, vaddr addr, MemOpIdx oi, /** * do_ld_mmio_beN: * @env: cpu context - * @p: translation parameters + * @full: page parameters * @ret_be: accumulated data + * @addr: virtual address + * @size: number of bytes * @mmu_idx: virtual address context * @ra: return address into tcg generated code, or 0 + * Context: iothread lock held * - * Load @p->size bytes from @p->addr, which is memory-mapped i/o. + * Load @size bytes from @addr, which is memory-mapped i/o. * The bytes are concatenated in big-endian order with @ret_be. */ -static uint64_t do_ld_mmio_beN(CPUArchState *env, MMULookupPageData *p, - uint64_t ret_be, int mmu_idx, - MMUAccessType type, uintptr_t ra) +static uint64_t do_ld_mmio_beN(CPUArchState *env, CPUTLBEntryFull *full, + uint64_t ret_be, vaddr addr, int size, + int mmu_idx, MMUAccessType type, uintptr_t ra) { - CPUTLBEntryFull *full = p->full; - vaddr addr = p->addr; - int i, size = p->size; - - QEMU_IOTHREAD_LOCK_GUARD(); - for (i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { uint8_t x = io_readx(env, full, mmu_idx, addr + i, ra, type, MO_UB); ret_be = (ret_be << 8) | x; } @@ -2232,7 +2230,9 @@ static uint64_t do_ld_beN(CPUArchState *env, MMULookupPageData *p, unsigned tmp, half_size; if (unlikely(p->flags & TLB_MMIO)) { - return do_ld_mmio_beN(env, p, ret_be, mmu_idx, type, ra); + QEMU_IOTHREAD_LOCK_GUARD(); + return do_ld_mmio_beN(env, p->full, ret_be, p->addr, p->size, + mmu_idx, type, ra); } /* @@ -2281,11 +2281,11 @@ static Int128 do_ld16_beN(CPUArchState *env, MMULookupPageData *p, MemOp atom; if (unlikely(p->flags & TLB_MMIO)) { - p->size = size - 8; - a = do_ld_mmio_beN(env, p, a, mmu_idx, MMU_DATA_LOAD, ra); - p->addr += p->size; - p->size = 8; - b = do_ld_mmio_beN(env, p, 0, mmu_idx, MMU_DATA_LOAD, ra); + QEMU_IOTHREAD_LOCK_GUARD(); + a = do_ld_mmio_beN(env, p->full, a, p->addr, size - 8, + mmu_idx, MMU_DATA_LOAD, ra); + b = do_ld_mmio_beN(env, p->full, 0, p->addr + 8, 8, + mmu_idx, MMU_DATA_LOAD, ra); return int128_make128(b, a); } @@ -2664,24 +2664,23 @@ Int128 cpu_ld16_mmu(CPUArchState *env, abi_ptr addr, /** * do_st_mmio_leN: * @env: cpu context - * @p: translation parameters + * @full: page parameters * @val_le: data to store + * @addr: virtual address + * @size: number of bytes * @mmu_idx: virtual address context * @ra: return address into tcg generated code, or 0 + * Context: iothread lock held * - * Store @p->size bytes at @p->addr, which is memory-mapped i/o. + * Store @size bytes at @addr, which is memory-mapped i/o. * The bytes to store are extracted in little-endian order from @val_le; * return the bytes of @val_le beyond @p->size that have not been stored. */ -static uint64_t do_st_mmio_leN(CPUArchState *env, MMULookupPageData *p, - uint64_t val_le, int mmu_idx, uintptr_t ra) +static uint64_t do_st_mmio_leN(CPUArchState *env, CPUTLBEntryFull *full, + uint64_t val_le, vaddr addr, int size, + int mmu_idx, uintptr_t ra) { - CPUTLBEntryFull *full = p->full; - vaddr addr = p->addr; - int i, size = p->size; - - QEMU_IOTHREAD_LOCK_GUARD(); - for (i = 0; i < size; i++, val_le >>= 8) { + for (int i = 0; i < size; i++, val_le >>= 8) { io_writex(env, full, mmu_idx, val_le, addr + i, ra, MO_UB); } return val_le; @@ -2698,7 +2697,9 @@ static uint64_t do_st_leN(CPUArchState *env, MMULookupPageData *p, unsigned tmp, half_size; if (unlikely(p->flags & TLB_MMIO)) { - return do_st_mmio_leN(env, p, val_le, mmu_idx, ra); + QEMU_IOTHREAD_LOCK_GUARD(); + return do_st_mmio_leN(env, p->full, val_le, p->addr, + p->size, mmu_idx, ra); } else if (unlikely(p->flags & TLB_DISCARD_WRITE)) { return val_le >> (p->size * 8); } @@ -2751,11 +2752,11 @@ static uint64_t do_st16_leN(CPUArchState *env, MMULookupPageData *p, MemOp atom; if (unlikely(p->flags & TLB_MMIO)) { - p->size = 8; - do_st_mmio_leN(env, p, int128_getlo(val_le), mmu_idx, ra); - p->size = size - 8; - p->addr += 8; - return do_st_mmio_leN(env, p, int128_gethi(val_le), mmu_idx, ra); + QEMU_IOTHREAD_LOCK_GUARD(); + do_st_mmio_leN(env, p->full, int128_getlo(val_le), + p->addr, 8, mmu_idx, ra); + return do_st_mmio_leN(env, p->full, int128_gethi(val_le), + p->addr + 8, size - 8, mmu_idx, ra); } else if (unlikely(p->flags & TLB_DISCARD_WRITE)) { return int128_gethi(val_le) >> ((size - 8) * 8); } From patchwork Sun Aug 6 03:36:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710863 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp825892rwb; Sat, 5 Aug 2023 20:38:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG+V2sZczb1xGZ+XUlbC8FxlAvYhJwLgauuL2KigDS2Cdt7WgxM5c8OzKhSgw1DD6N1J9P4 X-Received: by 2002:a05:620a:461e:b0:76c:e566:2dab with SMTP id br30-20020a05620a461e00b0076ce5662dabmr5097020qkb.33.1691293083779; Sat, 05 Aug 2023 20:38:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293083; cv=none; d=google.com; s=arc-20160816; b=bw01RSXnxxRGRDYRBcEH7QsVL/YfwOV8Kk6DZpKRN9fYLdDKEWbpzDqXxrJRLxcfTH Njtwjd7dBWThOpBq+81QhBeYi2DmNXAM33diW6wfb9Jqxty0rNjzX9+ly64ggXQVtpDf +QXmJ/tDZkBpGn/LCaowN8Z8Q4vdcheH1+rLl0FdcZYVguiAkywYpQRcx8ZX5PFjyMup QO4KWvkfGSnE07qd1D0I91uZjODO23hzdRGc4L5aMBwRnUhFAa7p8ipi61+DuOERZbSi 8uug9Zj7JH6hT2+kSpM/q8dKZH+HwajlJZ1M1HtlfY+iWEyHficjYfyFkXf/qqZWVBBA JVVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LfPki53EL/QBw74uxGxQNslYkA1KygGupPOLIF7ZjvY=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=tR+n6/ywT+XUQoKDsxtUINbMrJ1Yr0nipooKGbeGLIwdzvXf/js0LN4hXGthqvd38T o4QPL96q6Zk4aMoct1YOQCbLpiAYNrgkANoCUkuFZ7/Gm6vUCADfSDdSyWSn7a1ESx8Q 7DIU+IvgoJuM66henipVgAXTm4k6Vb0H9BaUDcdQI3278p22hTfWyUtjTH7r+tcbmHen OUtDPQJ8uJYrMfMT9ccdqMYWH9ovL1AqiNgEa02kuB3CslzWPB+278g6J4Y3lyL5mk++ xcfax7l7UXYKk15sd/Eo/eQc6h7FR0gMEGR5gDBGgFT3jm3PWrTuNOy5Ne7HQeicDZL/ y8vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DSJXV8cK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c24-20020a37e118000000b0076ca3265eccsi3186637qkm.704.2023.08.05.20.38.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:38:03 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DSJXV8cK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUa2-0003bg-Nd; Sat, 05 Aug 2023 23:37:22 -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 1qSUa1-0003Zg-CH for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:21 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUZz-0007Vu-4o for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:21 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-564ef63a010so150985a12.0 for ; Sat, 05 Aug 2023 20:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293038; x=1691897838; 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=DSJXV8cKp+mzujFEPHcOXlZzqvDsNdUj7y66MHQTtFEyhzhenQti4o7JkHjvdrbRE8 bXKhkuiTaxWIEwJVEiDg4+r7WfsKioo5cvIbeVs3wGXrokcpESLSKEg7A1wderNIIuZq fTMQ/IHpiAknB/pjnSjsOb51xF0FwhDajRlZayUyLvNC3jXHDoneTqGv7s/TM0LggXgD Cx1KN/4DYpH9eVt7gPrY8x2INGBxeg3CgghWFXK2u4VwYuOUFbTVFpC3ONaWkLdaAhsj HVCrera2RQcwy35eJmW7gynROn70NIPx6YDF43W+tFsUKNgOsbOq5T6PK4VrKaM+azLq 2Q6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293038; x=1691897838; 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=T+o18K75AMuiPrRl6u5AcRhvEJk7aXc3GhTpBzRHGsNYRZgz7+IAJT+dfbWjFD3eHc 8wshXFUZfM4yeRVh/kypoI4Uy1S1Ox7mljiHiULXL6oo3VhCqaXM3ReBPCBKlEOMAFws 51rEdX7jiny/4jXhLB/kQhQWyjA22/N4ulv/os63+jPCJf6ggmUkxpnpOahjC6I7JD3V FpSecL/h/KGoMmlPuNsT2YmL6Ly9nAIP5raOm8iTgWaCt3aBNo+1BLAqLfSVkTI7EfjD siRWI2nZruQQV9E+G3nYc/xi/pJKh+m/WKVXY3tP8Lu2kAcXBUOq55JQPnCjTKYEI9IZ Obqw== X-Gm-Message-State: AOJu0YwkD+a6lA2V8Qi5uqynoG3nPRf4E+sz68A5v6g+taRK5dUahWDA UPR1/Zc5ybZrbTGs6P4wqMnFeE1/X6Hse+VMonw= X-Received: by 2002:a17:90b:4b42:b0:268:2f6:61c4 with SMTP id mi2-20020a17090b4b4200b0026802f661c4mr4672210pjb.12.1691293037802; Sat, 05 Aug 2023 20:37:17 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 02/24] accel/tcg: Issue wider aligned i/o in do_{ld,st}_mmio_* Date: Sat, 5 Aug 2023 20:36:53 -0700 Message-Id: <20230806033715.244648-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org If the address and size are aligned, send larger chunks to the memory subsystem. This will be required to make more use of these helpers. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 76 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 23386ecfde..a308cb7534 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -2081,10 +2081,40 @@ static uint64_t do_ld_mmio_beN(CPUArchState *env, CPUTLBEntryFull *full, uint64_t ret_be, vaddr addr, int size, int mmu_idx, MMUAccessType type, uintptr_t ra) { - for (int i = 0; i < size; i++) { - uint8_t x = io_readx(env, full, mmu_idx, addr + i, ra, type, MO_UB); - ret_be = (ret_be << 8) | x; - } + uint64_t t; + + tcg_debug_assert(size > 0 && size <= 8); + do { + /* Read aligned pieces up to 8 bytes. */ + switch ((size | (int)addr) & 7) { + case 1: + case 3: + case 5: + case 7: + t = io_readx(env, full, mmu_idx, addr, ra, type, MO_UB); + ret_be = (ret_be << 8) | t; + size -= 1; + addr += 1; + break; + case 2: + case 6: + t = io_readx(env, full, mmu_idx, addr, ra, type, MO_BEUW); + ret_be = (ret_be << 16) | t; + size -= 2; + addr += 2; + break; + case 4: + t = io_readx(env, full, mmu_idx, addr, ra, type, MO_BEUL); + ret_be = (ret_be << 32) | t; + size -= 4; + addr += 4; + break; + case 0: + return io_readx(env, full, mmu_idx, addr, ra, type, MO_BEUQ); + default: + qemu_build_not_reached(); + } + } while (size); return ret_be; } @@ -2680,9 +2710,41 @@ static uint64_t do_st_mmio_leN(CPUArchState *env, CPUTLBEntryFull *full, uint64_t val_le, vaddr addr, int size, int mmu_idx, uintptr_t ra) { - for (int i = 0; i < size; i++, val_le >>= 8) { - io_writex(env, full, mmu_idx, val_le, addr + i, ra, MO_UB); - } + tcg_debug_assert(size > 0 && size <= 8); + + do { + /* Store aligned pieces up to 8 bytes. */ + switch ((size | (int)addr) & 7) { + case 1: + case 3: + case 5: + case 7: + io_writex(env, full, mmu_idx, val_le, addr, ra, MO_UB); + val_le >>= 8; + size -= 1; + addr += 1; + break; + case 2: + case 6: + io_writex(env, full, mmu_idx, val_le, addr, ra, MO_LEUW); + val_le >>= 16; + size -= 2; + addr += 2; + break; + case 4: + io_writex(env, full, mmu_idx, val_le, addr, ra, MO_LEUL); + val_le >>= 32; + size -= 4; + addr += 4; + break; + case 0: + io_writex(env, full, mmu_idx, val_le, addr, ra, MO_LEUQ); + return 0; + default: + qemu_build_not_reached(); + } + } while (size); + return val_le; } From patchwork Sun Aug 6 03:36:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710872 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826120rwb; Sat, 5 Aug 2023 20:38:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHoX0OlS6naK8TKsV7qEJmDA8JSAZfjy8+YAhCIvV2TutMVAoQItcC2K/zKVC+2RTwK1sK9 X-Received: by 2002:a05:6214:952:b0:635:e113:a0fe with SMTP id dn18-20020a056214095200b00635e113a0femr5649857qvb.26.1691293135718; Sat, 05 Aug 2023 20:38:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293135; cv=none; d=google.com; s=arc-20160816; b=nWl+So9WbGuxF8H25HTPR2bQ8mrczhtMWtv8LnudG+2Xx9XZ442PhbhpCzkLdNAuHp 2cH2NvlTt7TKW5EksMvkHYPI4WHAEL+XXpjT0Lh/XZJKP8UXXbJHwY91k5KGJ5TIycoV PxiEI5nnu5DEXmjK4E2nv86JUUFzOV3lyu+Nle0tXr1hQa84UEu37f9OVsuRWtyYJ7ja lEZkpWdxDB3ryWePJcCgljS/NlzVQu4nbpqQPaN30wgm58JG40goYoPdLqErWMAbYiFk pg/VgBQ7FLg2fo9f2Uc+v6L2Ma8rHCg9zEsB5Ns56/e6r19emSxDzsqUrakvU1HAj2GC cuwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+ogyDL6MEqk+X9fxmfimDp67js4GEaptZ9YAfaG485E=; fh=i1mkeM7bD/ppus3C3v+92ltBBCUUU0zBXrpbYjAjHqE=; b=updJtyqRQ+XfZbkLi4OMP5UVnhOSMh1m+u+NuPhwbJE9oi7WZ9cPszRuGAkkDGvx0z IYwRLCCY0X7R9aLq7BMTWvd87n+1t/LixArzsD4VyEN/M9Pz6KQd5+6JRuFl7pSSn0mq nejsdCTvi+SJVlE815FAzAEJXLgZp6yWwwwqHZVorrx/eShWAOn0byb+dnJPQGVmKrRa YjjNTJ0JIamDNEyqivhWTaMCiaP2sm3If3ia4JTGLjrb8MMRU6v8FE6Rf4O5AoUT5ahv EU/U1GvGhPA4POTq3I/XLo89vl5n8ODb0n8GxrBZEG3jc8dq4Ya3V174jK1SMI3JW5sq JtUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HfgWji21; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u10-20020a0cf1ca000000b00636c603c9aesi3089220qvl.525.2023.08.05.20.38.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:38:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HfgWji21; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUa3-0003cL-6o; Sat, 05 Aug 2023 23:37:23 -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 1qSUa2-0003Zp-0s for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:22 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUZz-0007W2-U9 for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:21 -0400 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-267f870e6ffso1845774a91.0 for ; Sat, 05 Aug 2023 20:37:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293038; x=1691897838; 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=HfgWji213wDej8djNt2WWlGLTkXoU7rrxJuFVplq8NdHgJr5ehLo9wghTjEgBd5XkK OM+fzTIu0Wx+NThffBKxS3048/t03oSQr2Hq0bxfciwO2oK2DyRJo5k+/uDNliXqEOzd 6ACrwtZHlr7nAQVGlcH+N9Gs2FFQkct0IbMrDzHSzbpmcsBFRLqDIdHwwLCxZg7I1g99 IbVH3tIgKm6G/LNCInaWb94nh+GxlXhWdstrKFb0BxAFN9H7h5NSKXPX8krjM/T6FkZz O6WdKb38uCv638FLPdyd8yyij6Y84YUFMWlnEgZFuc3S3foVOghCze+hWojabYy/+0Qj 1xAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293038; x=1691897838; 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=a/oY2rKFiQ6r8jOe2eXZz3Jcev+cKkHkXnrM2r9njdDzHK7HMgh+oK/PrZL/Uhbkwf cI57W7+xCt69XS4DydKT02CByDSeHMhnz8PZDRowbiu2c9GpET6rQTJxiug3gfFjO3Od WqDZOTgX5zp5+7fn9Mcb1a9O+Erwl39cUb34SxUBfwwXf6OJk5CY+sPkxZft9lxdRUci kAnGNRpk9ys/rEnaWUdEucoQnbyNDmJZRjaBx5FERS+SB04yXaKs6Q1dmmIiuMB4wxZp bQOs36oUi/cOQYz8kBH9oYaIRNkK2y4gASBV/weV6u5PyRga01W4tE4mr39dteskAyn0 miMA== X-Gm-Message-State: AOJu0YxD6v08ud+2YhmaK/EANZQB7m4Cpq2k+NF+n1YW7pOdr9cJ0lyn SSn8BkAI1YeUBI+YnZfSBg70VAIUxXwe4Af98Mg= X-Received: by 2002:a17:90a:1bc6:b0:267:e011:3e9a with SMTP id r6-20020a17090a1bc600b00267e0113e9amr4029993pjr.3.1691293038530; Sat, 05 Aug 2023 20:37:18 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 03/24] accel/tcg: Do not issue misaligned i/o Date: Sat, 5 Aug 2023 20:36:54 -0700 Message-Id: <20230806033715.244648-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In the single-page case we were issuing misaligned i/o to the memory subsystem, which does not handle it properly. Split such accesses via do_{ld,st}_mmio_*. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1800 Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 118 +++++++++++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 46 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index a308cb7534..4b1bfaa53d 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -2370,16 +2370,20 @@ static uint8_t do_ld_1(CPUArchState *env, MMULookupPageData *p, int mmu_idx, static uint16_t do_ld_2(CPUArchState *env, MMULookupPageData *p, int mmu_idx, MMUAccessType type, MemOp memop, uintptr_t ra) { - uint64_t ret; + uint16_t ret; if (unlikely(p->flags & TLB_MMIO)) { - return io_readx(env, p->full, mmu_idx, p->addr, ra, type, memop); - } - - /* Perform the load host endian, then swap if necessary. */ - ret = load_atom_2(env, ra, p->haddr, memop); - if (memop & MO_BSWAP) { - ret = bswap16(ret); + QEMU_IOTHREAD_LOCK_GUARD(); + ret = do_ld_mmio_beN(env, p->full, 0, p->addr, 2, mmu_idx, type, ra); + if ((memop & MO_BSWAP) == MO_LE) { + ret = bswap16(ret); + } + } else { + /* Perform the load host endian, then swap if necessary. */ + ret = load_atom_2(env, ra, p->haddr, memop); + if (memop & MO_BSWAP) { + ret = bswap16(ret); + } } return ret; } @@ -2390,13 +2394,17 @@ static uint32_t do_ld_4(CPUArchState *env, MMULookupPageData *p, int mmu_idx, uint32_t ret; if (unlikely(p->flags & TLB_MMIO)) { - return io_readx(env, p->full, mmu_idx, p->addr, ra, type, memop); - } - - /* Perform the load host endian. */ - ret = load_atom_4(env, ra, p->haddr, memop); - if (memop & MO_BSWAP) { - ret = bswap32(ret); + QEMU_IOTHREAD_LOCK_GUARD(); + ret = do_ld_mmio_beN(env, p->full, 0, p->addr, 4, mmu_idx, type, ra); + if ((memop & MO_BSWAP) == MO_LE) { + ret = bswap32(ret); + } + } else { + /* Perform the load host endian. */ + ret = load_atom_4(env, ra, p->haddr, memop); + if (memop & MO_BSWAP) { + ret = bswap32(ret); + } } return ret; } @@ -2407,13 +2415,17 @@ static uint64_t do_ld_8(CPUArchState *env, MMULookupPageData *p, int mmu_idx, uint64_t ret; if (unlikely(p->flags & TLB_MMIO)) { - return io_readx(env, p->full, mmu_idx, p->addr, ra, type, memop); - } - - /* Perform the load host endian. */ - ret = load_atom_8(env, ra, p->haddr, memop); - if (memop & MO_BSWAP) { - ret = bswap64(ret); + QEMU_IOTHREAD_LOCK_GUARD(); + ret = do_ld_mmio_beN(env, p->full, 0, p->addr, 8, mmu_idx, type, ra); + if ((memop & MO_BSWAP) == MO_LE) { + ret = bswap64(ret); + } + } else { + /* Perform the load host endian. */ + ret = load_atom_8(env, ra, p->haddr, memop); + if (memop & MO_BSWAP) { + ret = bswap64(ret); + } } return ret; } @@ -2561,20 +2573,22 @@ static Int128 do_ld16_mmu(CPUArchState *env, vaddr addr, cpu_req_mo(TCG_MO_LD_LD | TCG_MO_ST_LD); crosspage = mmu_lookup(env, addr, oi, ra, MMU_DATA_LOAD, &l); if (likely(!crosspage)) { - /* Perform the load host endian. */ if (unlikely(l.page[0].flags & TLB_MMIO)) { QEMU_IOTHREAD_LOCK_GUARD(); - a = io_readx(env, l.page[0].full, l.mmu_idx, addr, - ra, MMU_DATA_LOAD, MO_64); - b = io_readx(env, l.page[0].full, l.mmu_idx, addr + 8, - ra, MMU_DATA_LOAD, MO_64); - ret = int128_make128(HOST_BIG_ENDIAN ? b : a, - HOST_BIG_ENDIAN ? a : b); + a = do_ld_mmio_beN(env, l.page[0].full, 0, addr, 8, + l.mmu_idx, MMU_DATA_LOAD, ra); + b = do_ld_mmio_beN(env, l.page[0].full, 0, addr + 8, 8, + l.mmu_idx, MMU_DATA_LOAD, ra); + ret = int128_make128(b, a); + if ((l.memop & MO_BSWAP) == MO_LE) { + ret = bswap128(ret); + } } else { + /* Perform the load host endian. */ ret = load_atom_16(env, ra, l.page[0].haddr, l.memop); - } - if (l.memop & MO_BSWAP) { - ret = bswap128(ret); + if (l.memop & MO_BSWAP) { + ret = bswap128(ret); + } } return ret; } @@ -2874,7 +2888,11 @@ static void do_st_2(CPUArchState *env, MMULookupPageData *p, uint16_t val, int mmu_idx, MemOp memop, uintptr_t ra) { if (unlikely(p->flags & TLB_MMIO)) { - io_writex(env, p->full, mmu_idx, val, p->addr, ra, memop); + if ((memop & MO_BSWAP) != MO_LE) { + val = bswap16(val); + } + QEMU_IOTHREAD_LOCK_GUARD(); + do_st_mmio_leN(env, p->full, val, p->addr, 2, mmu_idx, ra); } else if (unlikely(p->flags & TLB_DISCARD_WRITE)) { /* nothing */ } else { @@ -2890,7 +2908,11 @@ static void do_st_4(CPUArchState *env, MMULookupPageData *p, uint32_t val, int mmu_idx, MemOp memop, uintptr_t ra) { if (unlikely(p->flags & TLB_MMIO)) { - io_writex(env, p->full, mmu_idx, val, p->addr, ra, memop); + if ((memop & MO_BSWAP) != MO_LE) { + val = bswap32(val); + } + QEMU_IOTHREAD_LOCK_GUARD(); + do_st_mmio_leN(env, p->full, val, p->addr, 4, mmu_idx, ra); } else if (unlikely(p->flags & TLB_DISCARD_WRITE)) { /* nothing */ } else { @@ -2906,7 +2928,11 @@ static void do_st_8(CPUArchState *env, MMULookupPageData *p, uint64_t val, int mmu_idx, MemOp memop, uintptr_t ra) { if (unlikely(p->flags & TLB_MMIO)) { - io_writex(env, p->full, mmu_idx, val, p->addr, ra, memop); + if ((memop & MO_BSWAP) != MO_LE) { + val = bswap64(val); + } + QEMU_IOTHREAD_LOCK_GUARD(); + do_st_mmio_leN(env, p->full, val, p->addr, 8, mmu_idx, ra); } else if (unlikely(p->flags & TLB_DISCARD_WRITE)) { /* nothing */ } else { @@ -3029,22 +3055,22 @@ static void do_st16_mmu(CPUArchState *env, vaddr addr, Int128 val, cpu_req_mo(TCG_MO_LD_ST | TCG_MO_ST_ST); crosspage = mmu_lookup(env, addr, oi, ra, MMU_DATA_STORE, &l); if (likely(!crosspage)) { - /* Swap to host endian if necessary, then store. */ - if (l.memop & MO_BSWAP) { - val = bswap128(val); - } if (unlikely(l.page[0].flags & TLB_MMIO)) { - QEMU_IOTHREAD_LOCK_GUARD(); - if (HOST_BIG_ENDIAN) { - b = int128_getlo(val), a = int128_gethi(val); - } else { - a = int128_getlo(val), b = int128_gethi(val); + if ((l.memop & MO_BSWAP) != MO_LE) { + val = bswap128(val); } - io_writex(env, l.page[0].full, l.mmu_idx, a, addr, ra, MO_64); - io_writex(env, l.page[0].full, l.mmu_idx, b, addr + 8, ra, MO_64); + a = int128_getlo(val); + b = int128_gethi(val); + QEMU_IOTHREAD_LOCK_GUARD(); + do_st_mmio_leN(env, l.page[0].full, a, addr, 8, l.mmu_idx, ra); + do_st_mmio_leN(env, l.page[0].full, b, addr + 8, 8, l.mmu_idx, ra); } else if (unlikely(l.page[0].flags & TLB_DISCARD_WRITE)) { /* nothing */ } else { + /* Swap to host endian if necessary, then store. */ + if (l.memop & MO_BSWAP) { + val = bswap128(val); + } store_atom_16(env, ra, l.page[0].haddr, l.memop, val); } return; From patchwork Sun Aug 6 03:36:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710886 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp827147rwb; Sat, 5 Aug 2023 20:43:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE/0vUJEz88CjRPTJZ6RaKrA9AbonpFr1fesI3eM1QP03Kc8TObkq/A69WKJNIfGO4LfrTj X-Received: by 2002:ac8:5c13:0:b0:403:f45d:6baa with SMTP id i19-20020ac85c13000000b00403f45d6baamr8141533qti.32.1691293381104; Sat, 05 Aug 2023 20:43:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293381; cv=none; d=google.com; s=arc-20160816; b=nno/WLTrqdp33qs6O8YfTy6LQ/Am1x8Em0mhx0kd9FjfFNgO+5+3feYGd/i4/rDTOn Pa/VOh6iBJLiuB6yteVzG7AoBlLGty66vPK+UDss3iIVDjykm92RNqcyWeziB13jXw6s 8nTBFmvlcuZItnEHfcKzna03o03vW5opA30NcxcnosmRIWtXVpdeyroPn6lWuDO4E/Ew 2hVA9ZfeGioq+zYB/zFIDqWaiGzLF8BlsVvGlbIwbXe0MxtFKCU0fVY2kwBuiAmEaJj1 hMiUwg6CAnJwLHt7V70q6Qi6pZ4t5GguvgiK2d8IYchQ4u0ZNTXFoFhWnecz7yP0fRvp grFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PGTKa1g9aGwPuG4tk4crlE1qhIW/f2V62gcPYilpvuU=; fh=2tnQCPLqmUYA/BoQGVU30HXpDTpJUwyLa9MIUyZ/Rgw=; b=YoqYT354AT8xS3yid9FRegEMoWQuwLntKt2PQSkeyJiZPpHwW9BMDRgE9cXD/E1OV6 V8B0gD7KVx08lPpZNNm47JRiJcxPn+/ltdWfBo4tocB382bo3TDKYdn2qIo4v+RVYfge LqFE2Ans/O4ulQRf0ogbjwjJpYxRG4o/sTVqHs9m/aNw4oJvDHNMcKqP9ZkGDC/9tSg4 AteShW3+oQZWU2+FTgu1aDeF5aQ10vL1DWUZk0sTUqsguIG0LKBafV/Yhx/CUqQdNp23 oawu8xEXv+pWB3V3xdTsGBwYj5MBD4qzTr6ZhOGpFzQoEvS61Ixx32HIahc5xo+PNKrf PO0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eRiAju0g; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b3-20020ac87fc3000000b003e384f9d039si3445114qtk.336.2023.08.05.20.43.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:43:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eRiAju0g; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUa4-0003cu-PS; Sat, 05 Aug 2023 23:37: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 1qSUa2-0003Zt-6S for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:22 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUa0-0007WF-KK for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:21 -0400 Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-26854159c05so1828867a91.2 for ; Sat, 05 Aug 2023 20:37:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293039; x=1691897839; 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=eRiAju0gWTsQuqYxsso8xl9xzggXxTNAthvnXoONu8Tuh9SHwwk25DNtJhb0hJALrC aki3q16tBtJTrgm+AOUwqkedhD/TH0q9UTQ9tC1PUCPPrQYJWIlOJcv6995zPR7ie3Sf y3OsuEvKI1ePtLM2qeqxfuH+6RLQDk77Oe0jfU4pbakcnVOqvYiFHFm6Tb14hK23z3Wd 0QuDjtLcg4YAGc5bZknZJb2B/M24M0zz4Hb0SaRMh0Sn+FVfY5atfJpbdqxU0Z+nHtku 52EEL7RxwuRAIy5qnCnmI5+isRqNMEg7EOZh6BtsL58Sg9PawMim+yNs0Gvs0xDcT/oI 4mSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293039; x=1691897839; 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=e3xCvMPR2QvU0ZoGjkYvZTlhoRm648rtGIx0WjljAHXtdkKetNwuPOZLKnGFGyoX3z ak5ZjbpAy1sEYnAwsJiY7kZSU/igRUHaMxX7L8OKqL9MaR1vOFscM+dtnTy5C6sNTTvk GTuQM1XwspzMFcjsXoQ/KcHyTmTP7JaLTEhahUAAdR6z8L/7AmhQNHYIc6WlrWK0pD4A u1CuhJ7RmnDtNT8WT23KhM84VzBm9FTJxvUEt9CoVXvKlngWjjjdsyj38CK7fLzSqejP Nr/KZIVX7sc5tTQ/83nSthD0WfaYyGWGMEVOKfPn5tcNtyxkIzWJxHiFoM6zaqCby7UR AoLg== X-Gm-Message-State: AOJu0YzdClTiHQKhw0n2b892g2EYbMWC6iRvUq9LfYB/NI+rHu/vKoKR XZm3XYFiIamDvnLeqeNwzKly/GmvGazZ2sGl178= X-Received: by 2002:a17:90b:3755:b0:263:fc43:5f39 with SMTP id ne21-20020a17090b375500b00263fc435f39mr4295795pjb.13.1691293039417; Sat, 05 Aug 2023 20:37:19 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Matheus Tavares Bernardino , Ilya Leoshkevich Subject: [PULL 04/24] gdbstub: use 0 ("any process") on packets with no PID Date: Sat, 5 Aug 2023 20:36:55 -0700 Message-Id: <20230806033715.244648-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1034.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Matheus Tavares Bernardino Previously, qemu-user would always report PID 1 to GDB. This was changed at dc14a7a6e9 (gdbstub: Report the actual qemu-user pid, 2023-06-30), but read_thread_id() still considers GDB packets with "no PID" as "PID 1", which is not the qemu-user PID. Fix that by parsing "no PID" as "0", which the GDB Remote Protocol defines as "any process". Note that this should have no effect for system emulation as, in this case, gdb_create_default_process() will assign PID 1 for the first process and that is what the gdbstub uses for GDB requests with no PID, or PID 0. This issue was found with hexagon-lldb, which sends a "Hg" packet with only the thread-id, but no process-id, leading to the invalid usage of "PID 1" by qemu-hexagon and a subsequent "E22" reply. Signed-off-by: Matheus Tavares Bernardino Acked-by: Ilya Leoshkevich Message-Id: <78a3b06f6ab90a7ff8e73ae14a996eb27ec76c85.1690904195.git.quic_mathbern@quicinc.com> Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- gdbstub/gdbstub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index ce8b42eb15..e74ecc78cc 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -537,7 +537,7 @@ static GDBThreadIdKind read_thread_id(const char *buf, const char **end_buf, /* Skip '.' */ buf++; } else { - p = 1; + p = 0; } ret = qemu_strtoul(buf, &buf, 16, &t); From patchwork Sun Aug 6 03:36:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710885 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp827088rwb; Sat, 5 Aug 2023 20:42:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGb9SlGuTGsW9jq9LNck1t02FiUrw/T/LtpVTJVRI6KSbZ8cIB6+kCqf9OX22+Z9qjAo8Zc X-Received: by 2002:a05:620a:40c4:b0:767:dfcb:7094 with SMTP id g4-20020a05620a40c400b00767dfcb7094mr7775458qko.52.1691293364758; Sat, 05 Aug 2023 20:42:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293364; cv=none; d=google.com; s=arc-20160816; b=hU9ShmWtExybQVSemXWtGxcsaxjDg7/M4if6xs+8Z9zN6q5KgWQG1WexT6JWK/oMlu XM3mgMcqZuir1u7tl1bijYkKTK2HOEcqxWRZJuHzU9uopkTbY7MvMK1VewQWfyWxKoA5 cUd+M+RMKOey0mOBEfHFMSKrUWlfpN96viYRg3Ia0FF/cqu/zj9Csq37WoP847tM782Q URvIL6JcRu7Jy6Umoq0FM1MI2Adr3zi3VN+qcu9Yl/KHa0uZvvtn3b/XiMQU7fm8CCjt QitxBkT1MvfqsYNW44W1t1C9HrvIX6ERk1KL3LjYGYnt/8ZaPMxzne/ADi9kOCjcQU4K zJXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9hdHwW/RvIed/+EnufWmWBI5tRDE8abmk2/NQyBO25E=; fh=evWk6bomlkFU5CSlcGEbB9y45J8nz+qeJ58iBBz7OL4=; b=YfdOdEyG1ACNK9GahVbznVUjwZYPku0dl5xBVkoqegDN/2PJmIsGH8nsgxzbUWbZZy vi8KVoeTmXrZuhCHLPoPEiSWlOX6/+dVzblEkw5AbUVeUYdDKRu/0ZEkbdOznDlrG5x0 11s/2ASwbr+E5FSq5Z+XsQlOoTlVLbdbeodiwbBu+xFwA3JWbQ8bxV7LiPaPgW9Xs2b4 arz1Idc+VpKLjyiGETPCt/sywIUQA+fleT5NGBlDIo8KUqNdUpvHB08UgD+gzTVnuGRj 1lEyTpwJVDX7ghlo53+xCQr53bFbc+zzvcDZLrwWNsPz7D1Hmt01CKLK/hOt+Iho6OpW dq5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x2y0mcyl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u19-20020a05620a121300b0075cf18aacaasi3171469qkj.328.2023.08.05.20.42.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:42:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x2y0mcyl; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUa4-0003ca-Hx; Sat, 05 Aug 2023 23:37: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 1qSUa3-0003cN-AR for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:23 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUa1-0007We-Mz for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:23 -0400 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-53482b44007so1893071a12.2 for ; Sat, 05 Aug 2023 20:37:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293040; x=1691897840; 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=x2y0mcylR08z82S81nt+uxpnFQEPS/6RZCpX5qz+p2kNgHElMGgrDYZFD/i5JXFuy4 Yurd0qW1jwJzlsjbIZZx/JpCMUymPwfwB2XavBsltw8THKtc0oFHba14H3eFWUi6Vi3w egouuTi5AF3GLi6gKXeDixw68UP+dDSNYZxi5NBEsGzyvSYs1nITcLWZMJt6I1zQVOBd A8WH9zqFj4a60LfcW0IveaibSTTx95/k0yxtxDdfNMnxnOaV6E8SZWdMP9mcDsQaTo2S P2Yf2I3riKz2ES2X4lFGi4VAqRVW8sOtT63shgSufHAFJX9ygPgIF82U9vuLwJb5S2Qx eaNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293040; x=1691897840; 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=jpuGRn2xqEtUotbmZQSY8ScaIBmP6+J427BFpV5TbsuMofPSP3dBPmndhg7/OQYbzX J2983yF3o2dVrfp4CNw4SkacdL8vvOfdqQzCTH2jRbb3nc6mNXIQFwirguv2CbY478i1 5zv3yzoVpwalM/gogiXNr26xqgXnqiLW2r8ciV6oFNjU7JtPcFg8CLwgAcTwWTggPg5Y 4M93ArlDvUyaeeNXStXYTqUK3k9DlIPP6Mq4gt/p2tp21c9d4YAA0y0TqZjXBESNTq5h pK/Qs1aHxs16kescFssqcZr1HDYhMN9Xo2XSzK6VPCB0CtDMdCxot2Myn840k0oZmjOs 1JCw== X-Gm-Message-State: AOJu0YzkoDPWysbOjl3rIdgOO5Rd89/2/sqCyLM/JxBKZNh+o164g1TZ 0cogZRaGfY2eqX2ePe1j1h010CQ3OMns2k0kcBQ= X-Received: by 2002:a17:90a:1c09:b0:269:5821:5808 with SMTP id s9-20020a17090a1c0900b0026958215808mr18801pjs.32.1691293040326; Sat, 05 Aug 2023 20:37:20 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Akihiko Odaki Subject: [PULL 05/24] linux-user: Unset MAP_FIXED_NOREPLACE for host Date: Sat, 5 Aug 2023 20:36:56 -0700 Message-Id: <20230806033715.244648-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki Passing MAP_FIXED_NOREPLACE to host will fail for reserved_va because the address space is reserved with mmap. Replace it with MAP_FIXED in that case. Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-2-akihiko.odaki@daynix.com> [rth: Expand inline commentary.] Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- linux-user/mmap.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index a5dfb56545..a11c630a7b 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -603,11 +603,26 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, goto fail; } - /* Validate that the chosen range is empty. */ - if ((flags & MAP_FIXED_NOREPLACE) - && !page_check_range_empty(start, last)) { - errno = EEXIST; - goto fail; + if (flags & MAP_FIXED_NOREPLACE) { + /* Validate that the chosen range is empty. */ + if (!page_check_range_empty(start, last)) { + errno = EEXIST; + goto fail; + } + + /* + * With reserved_va, the entire address space is mmaped in the + * host to ensure it isn't accidentally used for something else. + * We have just checked that the guest address is not mapped + * within the guest, but need to replace the host reservation. + * + * Without reserved_va, despite the guest address check above, + * keep MAP_FIXED_NOREPLACE so that the guest does not overwrite + * any host address mappings. + */ + if (reserved_va) { + flags = (flags & ~MAP_FIXED_NOREPLACE) | MAP_FIXED; + } } /* From patchwork Sun Aug 6 03:36:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710876 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826231rwb; Sat, 5 Aug 2023 20:39:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPXhDrOoAE58esYlOcTFIHC8XSS2DltK7zjJUCdtyK3QtbY30tFdyuHjJUXkKCBDh+9J1J X-Received: by 2002:a05:620a:440a:b0:767:8546:b374 with SMTP id v10-20020a05620a440a00b007678546b374mr4974469qkp.14.1691293172241; Sat, 05 Aug 2023 20:39:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293172; cv=none; d=google.com; s=arc-20160816; b=k/ktjUmO5wFArXeqcbIzFN9RdFf4EHTdHO9y1nuGjAUmkU80P9jGLYzZkKl5J7IIeL 1ZhaHcOAa56jw8HvCqTEfdPrxEk/TMjA1mbmk9nB9Cn5cyPsRtH1XqSIw0xTkQx3pPmr ANLV0zyB1uzwp3LrPYdRzfYM0Vklx4MjRLxlIFq7UIP+3Sr2d0cGYBqsEhyVmQZQMnz8 3bnv0PlDDvQai1o685n40+v3VSz1sXunS7OMdX1ruY5HtimLqhMDfSPlB2Hf+mO/5OyT eSV5TuQPfioS/+J3ZgV6TX1skZJMjUEaADknupuZHNueaCR8JSDJoec7qYBNxwCiziEf FPJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Y+al/bCM9dfQjUvbH6ERA5E1FapPNk6WKGGZIMvtMEA=; fh=evWk6bomlkFU5CSlcGEbB9y45J8nz+qeJ58iBBz7OL4=; b=1LpS1sF2h9qCgGzBk63Rn/rmk9FL4Fj0A2jTE8ARHWNowYXoFA42G6Ck1rz0P4S9v/ xIm8nsDsyZdlnaVWJ1QuVt9sLdo8cobp7EQ9/GbAeUq5s/fjbGK9LP30vz3e/MwgQyL/ YpQvLWV+Tj6JR0L39rgHdgjgMGugSrigJvoKtp4G58SamTZjU8E8Wur9TiNKSY2idFiV nHlBeVV6up0+F3ysYtW4mNeAGFoTlxvhxz7XBf7Br9iHjLLanRUNCT1QEAQ8MnpWXIvS xoRQT7Y7psxWIXKM6tjMVS5E3/YsSdJdvLsM+xC6T9aOq+PBssP/MeALvV/YQiJ9YJNW suqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Z6EF2Sf0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t128-20020ae9df86000000b00768064b6b5bsi3167198qkf.755.2023.08.05.20.39.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:39:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Z6EF2Sf0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUa6-0003e0-4P; Sat, 05 Aug 2023 23:37: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 1qSUa4-0003ct-Ne for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:24 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUa2-0007Wz-PE for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:24 -0400 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-564ef63a010so150994a12.0 for ; Sat, 05 Aug 2023 20:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293041; x=1691897841; 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=Z6EF2Sf0dU/8E+SPlQPBdWKP+TPG6VnwppJXQ3uUy8Bc2zcbW6CnsRa6482Z74/ZMp +UxmqedwJQbsNmWCeNoX9OQIjf4owyYQihCnTBMKsjrCae9bXRgOCjC+xc+50nL63sm+ 3kf0okqRV2C6Z7efjbLyYBTObkrXUeDkuVbjWbifVhtQDKo+Jpt3xHvv8R4eXhGfuEwp ho06D79uKXjgNL5eEcMFKG0MrusQriTzx8xzjzklfnWCzp/bJwLaG57tS/Ndfy8YkmyQ O7PVPzBUseqqyL8MWeoiJpVA2gwbAyXBGKiMGRv6e/QJdoKFIjo3BaGfih6qDl/x5hTZ N9tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293041; x=1691897841; 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=e7NAPZ94qRzMutIy5md1HTjHjMTOJi/usT/8fTeswQDFfOsUztDaCrEbTOri9MxP8Q ypOsl6EVkwm8lWeMZBLOCWbA1JKOycbXCvogQ8qgq57D7fJ5T7LMR8p8TkpNq+WKgkqv QrFrUP0JDcQ8xJfiPcTtgB06yepYoGGmH7bSUI+e/EZnVT8yMg4AMDWQJ60040Y+bj3T tzy7U/CM6+RIEApfa5afycGQWyva2LuXSiSaUPkPrD6ZUUSpZCN3N6LXqpDe0ohJK8Hp ZK+SyDRd48ob/wm35/J4ZTwy3oVuyHrNOjUHqBkeY3U5DS3f3ZcfZqq5vkDTmSBa3lnF zCqA== X-Gm-Message-State: AOJu0Yz2TFi1A6iJj2d2uZquFJ+30IMsRwLNMciN/amYoEI3Z96qcFG3 goL1JT7o5za4UDA8gEHOHKMFnjK7eFuV4EMFgKU= X-Received: by 2002:a17:90a:5512:b0:260:a8da:536c with SMTP id b18-20020a17090a551200b00260a8da536cmr4672093pji.23.1691293041161; Sat, 05 Aug 2023 20:37:21 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Akihiko Odaki Subject: [PULL 06/24] linux-user: Fix MAP_FIXED_NOREPLACE on old kernels Date: Sat, 5 Aug 2023 20:36:57 -0700 Message-Id: <20230806033715.244648-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki The man page states: > Note that older kernels which do not recognize the MAP_FIXED_NOREPLACE > flag will typically (upon detecting a collision with a preexisting > mapping) fall back to a “non-MAP_FIXED” type of behavior: they will > return an address that is different from the requested address. > Therefore, backward-compatible software should check the returned > address against the requested address. https://man7.org/linux/man-pages/man2/mmap.2.html Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-3-akihiko.odaki@daynix.com> Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- linux-user/mmap.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index a11c630a7b..90b3ef2140 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -263,7 +263,11 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, void *p = mmap(host_start, qemu_host_page_size, target_to_host_prot(prot), flags | MAP_ANONYMOUS, -1, 0); - if (p == MAP_FAILED) { + if (p != host_start) { + if (p != MAP_FAILED) { + munmap(p, qemu_host_page_size); + errno = EEXIST; + } return false; } prot_old = prot; @@ -687,17 +691,25 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int target_prot, /* map the middle (easier) */ if (real_start < real_last) { - void *p; + void *p, *want_p; off_t offset1; + size_t len1; if (flags & MAP_ANONYMOUS) { offset1 = 0; } else { offset1 = offset + real_start - start; } - p = mmap(g2h_untagged(real_start), real_last - real_start + 1, - target_to_host_prot(target_prot), flags, fd, offset1); - if (p == MAP_FAILED) { + len1 = real_last - real_start + 1; + want_p = g2h_untagged(real_start); + + p = mmap(want_p, len1, target_to_host_prot(target_prot), + flags, fd, offset1); + if (p != want_p) { + if (p != MAP_FAILED) { + munmap(p, len1); + errno = EEXIST; + } goto fail; } passthrough_start = real_start; From patchwork Sun Aug 6 03:36:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710879 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826417rwb; Sat, 5 Aug 2023 20:40:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGX7A083BFXjNcyaYrS8LJa1JeOxMk0oo+zIkhhqZWfLcwxhvmF6JkeedBi7VM/tsLOF5td X-Received: by 2002:a05:620a:29d1:b0:768:11ff:7899 with SMTP id s17-20020a05620a29d100b0076811ff7899mr9099881qkp.64.1691293210603; Sat, 05 Aug 2023 20:40:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293210; cv=none; d=google.com; s=arc-20160816; b=P9mRcSNkLJWUqzPvOhPCF9Tdj/Pl/AvA4pw+IxT+ZAzfaVjK1R8UCpABQ+QLLTJW9H fFFjmv7Ez1wn+5Mugq8ELXow1CKI68vxE7OZFTq0/lJbQ5qj0MKhZoFWUoZeX1d54nOK 1p/fZSyNYIIgRvNFX2XjSCniS5YxHQbBe5G56e106S/thokBPlGPs0tci7K4+CZ2ktU8 erWiMy0dSf4zHwN2ArPIi6bz6hvreZ2AFeTidarK2xYZmgUGJKGBi3AbElzzRS6ixotn d+c/KvtbQ399oe3nvCicE8xeAIw3VqG1YIiUUhKc92wolI/exYa7T0Eb3AyQ95zD22zN DlZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zGlGyVbf5mAt3X+pirtJo2XZVAZPR2luQo7KvVPWG+g=; fh=KbMqH8mq9CYjRSCjjAD/0kWfnvdKe1C4f7CRd7AraEQ=; b=t/9yVbnrIe2xOA7QeFA3XHY8xT7EsuF4T0iYCt+INRWmWCDiBKXCe60QmU5ROjnFxn aIs5L+7VMZFb7MTQr6NbaIWr5NTFFK7zoptz+7iUPptDFlBuzS4FZ/cBNtkUoGS27jKr H7Y2E6tqnqyQKdHgvD2cZv63H5Zzo/o7G4ZC5Dwfuw6bkYzXCh4LFjAL8Pxmx6lxkbCu +IetZ20CScFFFIROFADuVgHYQQC3treV/YHb9rCdwZwwIhA8PyEmDLG5vTl/QFw6N+Qa WvTbZC5mWYBP+lbxIDUu6ySAxRHlbXxXz3CsDh1u246F6O3Mr1WP2ymtGtuFCy/s8Vhl +3Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=efPZlL53; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ty10-20020a05620a3f4a00b0074ced1ef870si3199063qkn.650.2023.08.05.20.40.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:40:10 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=efPZlL53; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUa7-0003ej-HO; Sat, 05 Aug 2023 23:37: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 1qSUa5-0003di-R0 for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:25 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUa4-0007XJ-9W for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:25 -0400 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-26813478800so1955245a91.1 for ; Sat, 05 Aug 2023 20:37:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293042; x=1691897842; 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=efPZlL53myMCIQE9tVKG0whB4O+nv6ewJYmCie8Xi8+I5rB2wtoqo3VE2SD2adP+Bz WUylhQpxkBvwiPliKQhN68r/EWuiszIdvM7I05h27floRwf2LPoiTlvvwQnGs/8KlYRD vNJnnoprxoDegqMjQl+GKYEmlqCljbqjVTcigLBo63zvANzczhH2RG/xOalksdewjYed zjZN8pQjFQmpt9MJn1c6nmPWWvhXqrUjcPihy9dQM4IA6+bb7z78E/3KlWvCeGGhyAo3 1ewBZHwXwfvggwwmPOvsQeJI5ae7F4JfD4NYGhCQlx5PLXE4Uq1FM/sbO5d0vRWwQyso f91Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293042; x=1691897842; 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=EdL0fY2f8QW/jaRj01Z5Uf1J+UshMZbJmNDBRMUvT9l2LovzCMWUlNuVNzgt60InOt Sj1ejXPpOVwE1LOinvnhqh2AGyFdtskq6vdvX2sLzFhkkBXDEYH7Dl3Hc5EqOpZz3Rrf 9kJJbO50+G7ZXp97nli1Ca0jkbCWsinnwJiDQHNfs6AaUT7fJPZGZe6qqaIl+VRpNfTd 4iy5Q/W+Ccx5lyJ7ZWnCGMy+BlktvX6PZoTDD4y52T/S8REt0/l2qYnbowjs0ozt1hnO 4Q5zsA3TVSAwc1aJ6XLP9KiUv0f8o2NYy/pc+PCHf2TShLpk6DQfB2F5+/EUtfRh8uRl vAFA== X-Gm-Message-State: AOJu0YzL3yHaJehbEE2vAso2+HCDl+ysIixTuuJVJFgVrC4Nhcerdjr+ 0DFcY8dyiBRiqLb6hb+lsUuaiNuM87+zbwfjjqE= X-Received: by 2002:a17:90a:ce96:b0:262:e564:3ecb with SMTP id g22-20020a17090ace9600b00262e5643ecbmr5154812pju.36.1691293042111; Sat, 05 Aug 2023 20:37:22 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Helge Deller Subject: [PULL 07/24] linux-user: Do not call get_errno() in do_brk() Date: Sat, 5 Aug 2023 20:36:58 -0700 Message-Id: <20230806033715.244648-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki Later the returned value is compared with -1, and negated errno is not expected. Fixes: 00faf08c95 ("linux-user: Don't use MAP_FIXED in do_brk()") Reviewed-by: Helge Deller Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-4-akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson --- linux-user/syscall.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 95727a816a..b9d2ec02f9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -862,9 +862,9 @@ abi_long do_brk(abi_ulong brk_val) */ if (new_host_brk_page > brk_page) { new_alloc_size = new_host_brk_page - brk_page; - mapped_addr = get_errno(target_mmap(brk_page, new_alloc_size, - PROT_READ|PROT_WRITE, - MAP_ANON|MAP_PRIVATE, 0, 0)); + mapped_addr = target_mmap(brk_page, new_alloc_size, + PROT_READ|PROT_WRITE, + MAP_ANON|MAP_PRIVATE, 0, 0); } else { new_alloc_size = 0; mapped_addr = brk_page; From patchwork Sun Aug 6 03:36:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710878 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826325rwb; Sat, 5 Aug 2023 20:39:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFRvkJ/mJkUZN7zytfoGdz06vPRmtar4AhTmaXLKy15xGjIaWBmKC7YKkTe1t59LauJBK17 X-Received: by 2002:a05:622a:1652:b0:40f:df95:213e with SMTP id y18-20020a05622a165200b0040fdf95213emr7012422qtj.58.1691293194229; Sat, 05 Aug 2023 20:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293194; cv=none; d=google.com; s=arc-20160816; b=R5W6d6WAOZ01if6dZz56wukWm2RRLu/1g1JBtl+6aQ0ByjLL1kaNQ9Q1JPD+0g04Tb Qq2JMAYXwwvMi1xvxO+atfLREUC6EiZHccvioLstscKL4bSchwWR8v5p78e/WNscejMt bO+4QYpUlNYeGqMxrwQevsv22y51PLrSsa93c0+BJGHh0jVmHc9MaArlVPZksME0PUfB V/TQeSYbFW0Nj41c/PaUbposgKf1yoMBocj0Hk5DxExYQIKWne1r03SxQ+Sv/JXG+m1N DEpUHBf4ayncAD7ncnXWmy0/kScQnkobMczVHs5YHsBlwItAmaBUqyGjZDogkfTQPpCK mPrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=U8M/sECGKblXQECxwhiXY/mNUP2fHciHERdH2OiT8nA=; fh=evWk6bomlkFU5CSlcGEbB9y45J8nz+qeJ58iBBz7OL4=; b=No20SQ8QvAzbd72URHtHnGhvIVHOamTfWJ3mlogaLau1NW6COzlQWS08vv6IPVEGsj tIEn8O80yBUlxUMxbAQE/xhRP5LhCquVlisU9LktOKd3/mWxS3iXhwEcn75csktavg5J i20/mEMVY+hA0I+w8xUSJsET6HaVnc0v+jL8zEfcjMBwlSfiUoxGVpAb4r0XYeJSRONA 9Syp0S7Utv4KqgoFfZIlPubfeuAYgu/M6Gx7YSvxKk20UUJ+Bnpps26B1XFCMb36SY1u Cuowv0/s3hSzBmL+awXC+ghq9vepzIXYBU/cETr7dez5d/BufBA0iL8DPDYWWUkyxV7c 9miQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YhRjrWag; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s7-20020ac85cc7000000b00403b1d1599asi3444401qta.2.2023.08.05.20.39.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:39:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YhRjrWag; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUa7-0003eY-Bz; Sat, 05 Aug 2023 23:37: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 1qSUa5-0003dj-Rr for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:25 -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 1qSUa4-0007Xa-7n for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:25 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-686ea67195dso2458964b3a.2 for ; Sat, 05 Aug 2023 20:37:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293043; x=1691897843; 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=YhRjrWagjbp13SDviaVcq4SUcJqN8fFgf1kOTYRE5xGpALC0SXlo4yKQhBZT4RwFhd vPuXFP/fLW0Od+P3O7xl0j+H/OD0k5QaFEHqWjsfTxdBuPmx5MDfS6m89RgZ70/Emvza jrxbhtQaaRsXqia8xXY/ai24XnVOMHfDWM53mDmcws8obe15lffBBp5TgBp0s2wpyRit JWOPuFL1yZXe0yctgcRjswZUbYOKsdkgnvugCUKi7lQveUV83nOt04+w+eIagYiPxlXo YXSbMTXQBg2MlryX+UGwpJhPYRS40bJAsbiOkOngTAnIDqm6GtEm3CQM6R4n9g+6fTsX nvAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293043; x=1691897843; 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=fi5BmKlbNCrd/AAWJLgTJVOLJ/jMD5xpHj/ljuyWykla7RkAdN4JKDn1sg5gDNeisN 8OK41czmgFtFXRUThlExUg+oBUSjPqwV0gIKh2Ar9YdrroxNFxaa+H8G2IBzL6GPJedX gf4SNsadkTWDOg/9EuqzJYwx4zTRwYpBZA+KCs6fEHE5/T4XLCxI+SXhAPzrXFmY2caR LIK/QdZF8/10AdUw/Z/Vl7p0fXenraV2U6Vq+tGqxh05UlIbkiv/0XiACAmnEhW74l6M dPeYAgwN+czME238tSX7aUflipUQgWHNl0CJLfITvDiizBO+KXEXZwHUdmmPk+0+hWDR 7f2g== X-Gm-Message-State: AOJu0Yw5Z4hPWquzQYwnYrdAxjuf2RYIRUlHTp5d6qhLmuaCh0gTeKNh 2nW7YJf8Mak/om/7tke0/iQ8Mp5FZSV3KgJmhps= X-Received: by 2002:a17:903:2587:b0:1b8:b564:b531 with SMTP id jb7-20020a170903258700b001b8b564b531mr5870990plb.60.1691293042786; Sat, 05 Aug 2023 20:37:22 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Akihiko Odaki Subject: [PULL 08/24] linux-user: Use MAP_FIXED_NOREPLACE for do_brk() Date: Sat, 5 Aug 2023 20:36:59 -0700 Message-Id: <20230806033715.244648-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki MAP_FIXED_NOREPLACE can ensure the mapped address is fixed without concerning that the new mapping overwrites something else. Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-5-akihiko.odaki@daynix.com> [rth: Pass -1 as fd for MAP_ANON] Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- linux-user/syscall.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b9d2ec02f9..f64024273f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -854,17 +854,12 @@ abi_long do_brk(abi_ulong brk_val) return target_brk; } - /* We need to allocate more memory after the brk... Note that - * we don't use MAP_FIXED because that will map over the top of - * any existing mapping (like the one with the host libc or qemu - * itself); instead we treat "mapped but at wrong address" as - * a failure and unmap again. - */ if (new_host_brk_page > brk_page) { new_alloc_size = new_host_brk_page - brk_page; mapped_addr = target_mmap(brk_page, new_alloc_size, - PROT_READ|PROT_WRITE, - MAP_ANON|MAP_PRIVATE, 0, 0); + PROT_READ | PROT_WRITE, + MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRIVATE, + -1, 0); } else { new_alloc_size = 0; mapped_addr = brk_page; @@ -883,12 +878,6 @@ abi_long do_brk(abi_ulong brk_val) target_brk = brk_val; brk_page = new_host_brk_page; return target_brk; - } else if (mapped_addr != -1) { - /* Mapped but at wrong address, meaning there wasn't actually - * enough space for this brk. - */ - target_munmap(mapped_addr, new_alloc_size); - mapped_addr = -1; } #if defined(TARGET_ALPHA) From patchwork Sun Aug 6 03:37:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710868 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826041rwb; Sat, 5 Aug 2023 20:38:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYEWQyjb3j1a6u08cFTdcLOqzUfJVCAGNdqu2R1wGlzFEnyE9jkehAT6AMWWhUcC5rrf1Q X-Received: by 2002:a05:620a:3953:b0:76c:97b1:33b5 with SMTP id qs19-20020a05620a395300b0076c97b133b5mr7484600qkn.12.1691293117249; Sat, 05 Aug 2023 20:38:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293117; cv=none; d=google.com; s=arc-20160816; b=c08Ghl6kV2peF9dlraxRVKb/Bgsg7hTfx7ceBwgtiIg53yiWPrDTNnuRC8MpTVH1LF hTMscAVM9Gn2/Vw9lQzB+oYSfR6CAT4aMc0yv4nAmNmtgt9ELz20SkWjZEL+1ZBPgckT HHfeXzGKIM/FqRIxPwie6K1l7BV47zPv+Whi27XuKtA5OCbHinT0zhp3FwisRjRXGQaG VQa5vGv3yKxLbJS31zSsFb3g1eHvn5D5NFUM4tisVJMIkOXn4N1+YEFa354fmLyaSy1L L2Rfefz4rboEn+usSMDarDSppMaDxDo/RBK9v9XnQkVX3GbN969Wgb+vU8RGJMJJHfxX 67Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VNYrY2Waoll+LErzR9Xgbts1EKTxuONltL+p3Yeklu4=; fh=KbMqH8mq9CYjRSCjjAD/0kWfnvdKe1C4f7CRd7AraEQ=; b=yQib4JdM2BpDRiYNN6lHg1pSGmwejm8erK1t0Oe+FXqcC3pVsxL+ujtu4uvuFhPm94 8KUwNnm/cISdKqtNTdtevKTCcuQia6Co/n6H6rKV51sqMpgf5EFinHCHv5KJONCJLe6A 6cZrZIYkfA7AKAgeZ4gTccTkg/sJ4W+8CE7swv+jaKcmsKZnq19pw/vso87A39CaLSbk Md3dP4w+RPxwawPNAn8t00hdiUY0gZCIgK2uxiDprItN5uK1DhR+iVGGiXc9F8+lAvjQ vMXIDedJjCnwJltljjWvZ4cCCaX6YEjFuUYc8150Y9TmkMAmsZFfsHE5av+1n2fluty6 kkRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jvuBu+oi; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ea27-20020a05620a489b00b00767b9807535si3234323qkb.666.2023.08.05.20.38.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:38:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jvuBu+oi; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUa9-0003fJ-3d; Sat, 05 Aug 2023 23:37: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 1qSUa6-0003eA-V6 for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:26 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUa5-0007Xr-DG for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:26 -0400 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-26814e27a9eso1685285a91.0 for ; Sat, 05 Aug 2023 20:37:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293044; x=1691897844; 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=jvuBu+oiUXsexECcMGF/DL7Brf2aPF5l5SKDbNubqQx1A+QuXsL9YqVlp8ZqA2btjg gjDgS1wn0zR5aldc9ZVe41bvut3dSMIXe7Y30RbA1qQ+Wy8aYvujYmyUDfqubSdouKLf /8W6et5Ln6QOLgyhIl3xQjm2vvVXnYiNepcu25Nr2++tBwW4Lk67skKCWzj/OKMpr3IU vALUNIKHrpaL7a1DCEa/Pb1/NSblNF50F0ZOdskKVYJA6R17wtyLj54+OC+WI9MS1oKx SqK3VdBLuA6NX+py1Fv5E42sUFEpDTVSXRRwuw2qXDBOL/4uCaf5pkWxyvUmaOxqXeLQ IOuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293044; x=1691897844; 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=FLoEE9H+kdH80HFkLoAc+6Q4z21SrVhWQ7ioV1anRkd30ezA8k9Nxj7KqDgUo6x12N wzCPrrIvi+4IVEpQ3l8jpgFxvxrZKyV5vECC2KEkcaf5OEcJ1//b/k01nk0HkIrvZNwF rGCnGniQY1qBpdzanPrCqY3R7FvhqtHXSvXWp0tp+6v6pX1adHOtd5j8dTQaZk5MuOY5 R9dAkPqLogxOYU21HSIKaFXJIfSHGSTpB54ecqfmKf3g+ZLEXo6FKUUD6mNyTewOuCil ilYc44kjU8EICZ8TizQ1KNPpJVqxmEa2EBpmAX0k/45ek0YXha0YrDbGc5tlWscQbbRp WJAQ== X-Gm-Message-State: AOJu0YwuTUjBu7Ap5/1XxoLGub5kxIH1cNV1TU1S2z0Y+tu3efB3RQCu RMa7Lf5sxboYPqcCuHsYjeO3HqqC79okxfvL6iI= X-Received: by 2002:a17:90a:6c45:b0:263:fccf:8f6 with SMTP id x63-20020a17090a6c4500b00263fccf08f6mr4044567pjj.14.1691293043858; Sat, 05 Aug 2023 20:37:23 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Helge Deller Subject: [PULL 09/24] linux-user: Do nothing if too small brk is specified Date: Sat, 5 Aug 2023 20:37:00 -0700 Message-Id: <20230806033715.244648-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki Linux 6.4.7 does nothing when a value smaller than the initial brk is specified. Fixes: 86f04735ac ("linux-user: Fix brk() to release pages") Reviewed-by: Helge Deller Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-6-akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson --- linux-user/syscall.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f64024273f..e1436a3962 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -820,14 +820,14 @@ abi_long do_brk(abi_ulong brk_val) /* brk pointers are always untagged */ - /* return old brk value if brk_val unchanged or zero */ - if (!brk_val || brk_val == target_brk) { + /* return old brk value if brk_val unchanged */ + if (brk_val == target_brk) { return target_brk; } /* do not allow to shrink below initial brk value */ if (brk_val < initial_target_brk) { - brk_val = initial_target_brk; + return target_brk; } new_brk = TARGET_PAGE_ALIGN(brk_val); From patchwork Sun Aug 6 03:37:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710867 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826014rwb; Sat, 5 Aug 2023 20:38:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFfNjInPcQ+4dzUWQ9A/IGjh+bFDRKGJgH6DyvKnNMWyx4nAR63Fqb+k4xuUYcqvEgCoPPe X-Received: by 2002:a05:620a:2685:b0:76c:a9fb:6d07 with SMTP id c5-20020a05620a268500b0076ca9fb6d07mr6221688qkp.2.1691293111579; Sat, 05 Aug 2023 20:38:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293111; cv=none; d=google.com; s=arc-20160816; b=yOS8k9NZiyHSuVqaWjF/I4R+o8RVlhontYKdXs63n0vd6qXxOA7F+TMw20tDGOMN88 BPYeaVJE+qgwGu6+sW7cK67j2gJMW8SzR6a4PbeU1WdnMyxYPOtmsqJ0tSlNpkBmfZOa kPdkmjCemsARTehGzxpejqXDzkHi52mriIcR4y6LgTAVtfpIKDpzjPcJ+5IdKEMshpHI sWQqoFHbEL8ZN1W9KB3oYmZVQANcCp412G2c8dQCKwiVyI7y5QH+DzGjtHt2G4/64ABN 3fF/DI9ONLmAb4uWxd6WFjgUKwVMqNHxUc4S3hK0QgzzS9qS+pOFVhCDkH+TjgO7+HXE ynxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wcmdNjO5rFxrj9FLufrsNHQ94VqSwsdLVl0LIEVlaaw=; fh=evWk6bomlkFU5CSlcGEbB9y45J8nz+qeJ58iBBz7OL4=; b=0Qu5MdoR5hb1M3UCFdy7KBPJXWLEdoejbHmcUGSUxMSiynMX9cBZGEFyW+ASrWVGt9 KJHs2Gn03SMUG2qNr3ABYlZZaIlTkOtS+gKZXENvezeSyzVk8gpNnYlPh5UjyCjJqTL3 5aR7vcA8STAince5aKLzR+2GAgY51ogDzI3/xVQXJKxT2JeWQ1EoFDqPkbepk2P2sfAB ZWsMknLbkN4ViLbgt9RdRufXcvl95mzXlwQjzkUJsmY4F0xCPXR7MKTLwXmIk2kpZXje A+dF3nf2XXW9ymEXsUHfzGNA0m1JeiVLU08OAeFDTv7Ta9NHQeetZQuxjsbLme41i77A EnlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T7kc7cn7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ty3-20020a05620a3f4300b0076cb0e6c5f0si3169983qkn.151.2023.08.05.20.38.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:38:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=T7kc7cn7; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUa9-0003ft-O8; Sat, 05 Aug 2023 23:37: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 1qSUa7-0003el-PQ for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:27 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUa6-0007Y7-1U for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:27 -0400 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-563f4e49ff9so1960379a12.3 for ; Sat, 05 Aug 2023 20:37:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293045; x=1691897845; 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=T7kc7cn7101dlIC9J1hLhPHMqyZl4anighnPClj1wWH+MEdtyI68SgKGIb3cFYJT/9 cpeR4fLwm3CxOLQLl31n3ws3yY8Z64CFGmE5BP+BdlTS1AYtxdCF5bWTY2nFQ0fRGTi+ GtP8OR0kKKKl1I9MToxbrbd3sGEQcv+ADQv3uIHvpPsLBjKbDcCuEeASr3ljV4hdgPc4 +ztpCrKV/Dhx7bDQu08oPxset8LYxFcsjyJreXVD1iQltACAKj/hUnLCFHiEEmXCxaot M+g5qn5IEhgUUqjxgJd8WZ2UHdl7BucLriZ8guy7S7Ov0Xo2RFL2bZP3K/+WJLoy8Ido he7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293045; x=1691897845; 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=LUzw0Quy/IbiFAaXpt/uh9p62SuBc+utChfBpS17jon3++N1nged8BxqLrlIfX10QU 06+Y3G38oYQ+drFOANk5IJiwSnEE3ECXodzUbOlhKt8EvdPyTohlUUI+8614TXef8UVh D8rqpLxRLDjxHpjPZmJJfFki8E/CVN0Mo32R/i9+5sG0Kk9o6fChd8SSO1jqouiSnrk3 5c1wkIRxE7zMdaZro0sw0ojVcgyRzRX0cXioxgfidSz1Rqre2+FpToddbK45THRK7dJM 07v2ElfHoQZotx7y+v9FKJygu9cgtTVk56D3Hwtp2YrCofKs7o/sG6tb3c+jZ/jR6k7Z ToEw== X-Gm-Message-State: AOJu0YwpWLq+cuq+IcS/FFy2LNCokOJJA8euO0ReJ+Ll3oUKNXVYAdhd qlTkBYf246GaRZpeelc8YXx/UYdPMD0I1jbGT/U= X-Received: by 2002:a17:90a:2ca4:b0:268:3f6d:9751 with SMTP id n33-20020a17090a2ca400b002683f6d9751mr5715108pjd.23.1691293044763; Sat, 05 Aug 2023 20:37:24 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Akihiko Odaki Subject: [PULL 10/24] linux-user: Do not align brk with host page size Date: Sat, 5 Aug 2023 20:37:01 -0700 Message-Id: <20230806033715.244648-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Akihiko Odaki do_brk() minimizes calls into target_mmap() by aligning the address with host page size, which is potentially larger than the target page size. However, the current implementation of this optimization has two bugs: - The start of brk is rounded up with the host page size while brk advertises an address aligned with the target page size as the beginning of brk. This makes the beginning of brk unmapped. - Content clearing after mapping is flawed. The size to clear is specified as HOST_PAGE_ALIGN(brk_page) - brk_page, but brk_page is aligned with the host page size so it is always zero. This optimization actually has no practical benefit. It makes difference when brk() is called multiple times with values in a range of the host page size. However, sophisticated memory allocators try to avoid to make such frequent brk() calls. For example, glibc 2.37 calls brk() to shrink the heap only when there is a room more than 128 KiB. It is rare to have a page size larger than 128 KiB if it happens. Let's remove the optimization to fix the bugs and make the code simpler. Fixes: 86f04735ac ("linux-user: Fix brk() to release pages") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1616 Signed-off-by: Akihiko Odaki Message-Id: <20230802071754.14876-7-akihiko.odaki@daynix.com> Signed-off-by: Richard Henderson --- linux-user/elfload.c | 4 ++-- linux-user/syscall.c | 54 ++++++++++---------------------------------- 2 files changed, 14 insertions(+), 44 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 861ec07abc..2aee2298ec 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3678,8 +3678,8 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) * to mmap pages in this space. */ if (info->reserve_brk) { - abi_ulong start_brk = HOST_PAGE_ALIGN(info->brk); - abi_ulong end_brk = HOST_PAGE_ALIGN(info->brk + info->reserve_brk); + abi_ulong start_brk = TARGET_PAGE_ALIGN(info->brk); + abi_ulong end_brk = TARGET_PAGE_ALIGN(info->brk + info->reserve_brk); target_munmap(start_brk, end_brk - start_brk); } diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e1436a3962..7c2c2f6e2f 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -802,81 +802,51 @@ static inline int host_to_target_sock_type(int host_type) } static abi_ulong target_brk, initial_target_brk; -static abi_ulong brk_page; void target_set_brk(abi_ulong new_brk) { target_brk = TARGET_PAGE_ALIGN(new_brk); initial_target_brk = target_brk; - brk_page = HOST_PAGE_ALIGN(target_brk); } /* do_brk() must return target values and target errnos. */ abi_long do_brk(abi_ulong brk_val) { abi_long mapped_addr; - abi_ulong new_alloc_size; - abi_ulong new_brk, new_host_brk_page; + abi_ulong new_brk; + abi_ulong old_brk; /* brk pointers are always untagged */ - /* return old brk value if brk_val unchanged */ - if (brk_val == target_brk) { - return target_brk; - } - /* do not allow to shrink below initial brk value */ if (brk_val < initial_target_brk) { return target_brk; } new_brk = TARGET_PAGE_ALIGN(brk_val); - new_host_brk_page = HOST_PAGE_ALIGN(brk_val); + old_brk = TARGET_PAGE_ALIGN(target_brk); - /* brk_val and old target_brk might be on the same page */ - if (new_brk == TARGET_PAGE_ALIGN(target_brk)) { - /* empty remaining bytes in (possibly larger) host page */ - memset(g2h_untagged(new_brk), 0, new_host_brk_page - new_brk); + /* new and old target_brk might be on the same page */ + if (new_brk == old_brk) { target_brk = brk_val; return target_brk; } /* Release heap if necesary */ - if (new_brk < target_brk) { - /* empty remaining bytes in (possibly larger) host page */ - memset(g2h_untagged(new_brk), 0, new_host_brk_page - new_brk); - - /* free unused host pages and set new brk_page */ - target_munmap(new_host_brk_page, brk_page - new_host_brk_page); - brk_page = new_host_brk_page; + if (new_brk < old_brk) { + target_munmap(new_brk, old_brk - new_brk); target_brk = brk_val; return target_brk; } - if (new_host_brk_page > brk_page) { - new_alloc_size = new_host_brk_page - brk_page; - mapped_addr = target_mmap(brk_page, new_alloc_size, - PROT_READ | PROT_WRITE, - MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRIVATE, - -1, 0); - } else { - new_alloc_size = 0; - mapped_addr = brk_page; - } - - if (mapped_addr == brk_page) { - /* Heap contents are initialized to zero, as for anonymous - * mapped pages. Technically the new pages are already - * initialized to zero since they *are* anonymous mapped - * pages, however we have to take care with the contents that - * come from the remaining part of the previous page: it may - * contains garbage data due to a previous heap usage (grown - * then shrunken). */ - memset(g2h_untagged(brk_page), 0, HOST_PAGE_ALIGN(brk_page) - brk_page); + mapped_addr = target_mmap(old_brk, new_brk - old_brk, + PROT_READ | PROT_WRITE, + MAP_FIXED_NOREPLACE | MAP_ANON | MAP_PRIVATE, + -1, 0); + if (mapped_addr == old_brk) { target_brk = brk_val; - brk_page = new_host_brk_page; return target_brk; } From patchwork Sun Aug 6 03:37:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710866 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp825952rwb; Sat, 5 Aug 2023 20:38:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEXqKeXL4aUpRuAN8zpNPgDA3jeHhYbeEIPolIsMMdnPcUC0t3AradnlsGRgaNhDY/RzGux X-Received: by 2002:a05:6214:448b:b0:623:42c5:612f with SMTP id on11-20020a056214448b00b0062342c5612fmr4616367qvb.49.1691293097742; Sat, 05 Aug 2023 20:38:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293097; cv=none; d=google.com; s=arc-20160816; b=M4sZG3gJEdTWLpn8ORA8yWjxfAMVpXq4T3yuUP2rGZbDsrZXRAbUwyhO29BOxzhQWx MibEl34YNYGFldP78F0o8vp8Mxv2DwuvsV2ykqNEE+nfTj192c1HE+324F6XsMOToTQW YRP8KVDcWKWI1xcjWnZJVYZWZcV8bQnP4DVmO4ROnWTEWUxTZdwg+NeiwhS8ewM+gxeK vS5lTtecAFgw+j8y9k+yBtHHTXvb+tr6N+QvFAYfxwMZdtCWKrL4a5zVyhw+Rms+g3Rx 69NYITWbGZP5zs0vKI8znPNbyB9d1NmMe67/YbDHtPTh+Fy2rwOOEXEkmSDQejn81DO2 lZrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PiKvQ5TIjJkHeXd+ZGncRxkavk8D0Yfna3UAt9/lKq8=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=XuhQLGQhpaCh47VJoD00u1wT0Xkh4XQ3c1TtT+Pyt8ss6hgRF3xPJ962PY19evASfq 66OSaJgDAo5xydzZBHLMVWzw4ZdBxBbWMwzFRS3v6W4oY3h17DoViZQbnIVyejA+fpNf RHKgYjkzaj330AtjSd8dphmK1PEfdTo23FzOXBVb7FGNfgklJtD8JBdSwQ409mFmapUR 9/mIWuUarRB8aYRmlj+eYApGeM9yrvgghmo+uP0ejUzhHbhaRAspn/LDx/ZuDqxoOVNi 8ijKd+hgTwbssk1Vj6gvz8m6Mmff2L8U7fK9UAIpS9VPm4i6V3OXrWapA4EhN45gPmoP Q67A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aTEXjqbq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t16-20020a0cde10000000b0063d63a3f462si3207242qvk.82.2023.08.05.20.38.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:38:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aTEXjqbq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUa9-0003fx-VM; Sat, 05 Aug 2023 23:37: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 1qSUa8-0003f9-HG for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:28 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUa7-0007YS-1R for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:28 -0400 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-26837895fbbso2389965a91.3 for ; Sat, 05 Aug 2023 20:37:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293045; x=1691897845; 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=aTEXjqbqaO/SstStJeSHAiASAEmV8j9iYIROtfc8J8V+LtNdcknC2IQSKKHxskGL5P 2tRstoO21Zg6x4M44gqNLpYTKFCYfHPzOVaPF6iYjdptqZ2YyjyraB3y9PvitnmMtDHU CFZwhF6XJQ/2ZT+ag/3zMBHLoHol7RQ/R9SsbVx5+z8ARjAToRcovs2qtLBNprRRzjCp U2OfRaJehYUFsTw3/kS/099BgUOYFzMV2NEZCegzBWca6bUfKiBA/668QSm0lHL5R6D7 gIOZsWvqtEBwkI4Vu1XUFOpfeaKV40Q4CMarl8uQlDX87jfPCHzZC93hQs06kRF04IBQ RtkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293045; x=1691897845; 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=X4dTUYkdAvJYGEUinpB/50HA/qEuvKStSTW0FauO8jUQ21EZ4QOmby6LHmfc1dqx6y eCmNXixgZ9nSDhlD5Ue3qug5WeCa0S8mpvZ+8PpxA+PT57RR5Ay+4iFJMYMpmyDNZJz6 NmX61zk0XvPfqVuTqNiirt/weaZbSV1+CABDrvq7Gc4XSL37+6zR1qEKplO38OUVfVGu kG/TZSMo1Bv85L4qqzkAumEA/OKhd2LKh1tlddOWhiYVR0gl5hgfu3eu6FliQjTXXfjV tXvU1Lz66G1iKsw2iwrvycETyz5jFLpzkNJIeHliGaNWqvcx8dP4PXKjxDCR6piyHYM9 b5rA== X-Gm-Message-State: AOJu0Yw8oCbNScG0cQ8gV+R4WwfYAXOdEY9sHBgH4pPLJoSsUcMRM1ZR Ydf7H3rsyEI3Fn37twXBJWrjXULcaz8v0Qpm7Ts= X-Received: by 2002:a17:90a:7ace:b0:269:142e:c2ed with SMTP id b14-20020a17090a7ace00b00269142ec2edmr5728112pjl.37.1691293045572; Sat, 05 Aug 2023 20:37:25 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PULL 11/24] linux-user: Remove last_brk Date: Sat, 5 Aug 2023 20:37:02 -0700 Message-Id: <20230806033715.244648-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This variable is unused. Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/user-mmap.h | 1 - linux-user/mmap.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index 3fc986f92f..7265c2c116 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -26,7 +26,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, abi_ulong new_addr); abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice); -extern unsigned long last_brk; extern abi_ulong mmap_next_start; abi_ulong mmap_find_vma(abi_ulong, abi_ulong, abi_ulong); void mmap_fork_start(void); diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 90b3ef2140..eb04fab8ab 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -314,8 +314,6 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, #endif abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; -unsigned long last_brk; - /* * Subroutine of mmap_find_vma, used when we have pre-allocated * a chunk of guest address space. From patchwork Sun Aug 6 03:37:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710875 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826202rwb; Sat, 5 Aug 2023 20:39:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFYYuYWZ/InaNtSTPr+AVqcybO50eJcFYRuxd6xjX584bQ4ZycOLtfH+u+k+7GnP8AeZJL1 X-Received: by 2002:ac8:5dd2:0:b0:40f:e176:ddc5 with SMTP id e18-20020ac85dd2000000b0040fe176ddc5mr8206019qtx.34.1691293162821; Sat, 05 Aug 2023 20:39:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293162; cv=none; d=google.com; s=arc-20160816; b=wOa4zL1HXCqjJE3VJhw4Adi/45QH4jW/T/3ZLFKuD3EkRoJkmF1SW3vBBYGeKE393O 3NMS6+Vdfj9vU3gpCh2sLiwXFME/rPyXqatkiYwoy07ZaUO/dSh7AyKFwQvN68s2LIVf JELAacnLlumBs2JG8MG7rnphqn3iVI4IKXPj32f00n3j9ZGI4iA0Eg5aFG36Uhyxb/ha n64LRSDjwPHimG5zeY4CG45PVHwOcnIKNR47s5J4aNFVCjprvf16Qps1cs9qb817lbt7 I1umpX8pcTtszMJngdLqIqyGa0VeYBTPDuyjZAvO7Wfh6jlUGFN2FYfgMlquz99UBfg0 xdDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=XZm1OFwkD4B8Sj8o40TKDrmNFRuwUs1Ie6LEvKqa7G4=; fh=oYAd+8Lj9FKlReeF9hgENQXa3P4LhBP5C4njRBbobDA=; b=HGAi8JyEhyuCxNzy8QNx0LraJixvZ0xOpmz6Osndun9Rcki7YwUdUnQFSG2H02qdN7 0v0G1i0o7CMg6CBzPqZtxFssTcInh0G6u1XQanhuU81b0z99uUYMHBx77wbmEUs93Rrk rtKrvjHkUaFDwoC4ct/1/vfXOJ6hHx7tUXV/Ppg+huBz/tyQbBA3U+01uD7BgJNnYRYW j3uYUYbWCVSg1/3PBory3xEFGkX/4wOBu9eOjlDj3BSOh/NTDUVooHXT6jqdlQpZ22LN ZJWLzg/Xm1mF6+K5FcrIvYQLZSrBz2TxhbGwjhm2cP4DTk1qOYylcrpN1iiGTV0nzPXP OHzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZbWd5jB2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id u5-20020ac858c5000000b00403acdbb3a8si3346633qta.669.2023.08.05.20.39.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:39:22 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZbWd5jB2; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUaB-0003gK-M8; Sat, 05 Aug 2023 23:37:31 -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 1qSUa9-0003fI-0w for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:29 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUa7-0007Yb-JC for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:28 -0400 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-2680f27b52dso1967349a91.0 for ; Sat, 05 Aug 2023 20:37:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293046; x=1691897846; 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=ZbWd5jB2YZ6jGGpbje1Pu6cR8bNBepO67ZMqIVGmuKZ59EFVYgXAuhRzVA7GAScLNr R+RsCPpO1lGEWRmAX0Vp5QQZOqp7+R6oK9Fk21R5zWRGpKVhUCq/8oB7NYY0c4bUKETV uMrPYzbnWUhiflOQQSkh+mbZaB/76Uk0thvRf9DfG9qCfY2ZV5oPGJ6JP4OaPR5V3J8J 7mS2p0DrTWw3hwHqlmZgJE0L9ox+JS41SCzvkd/2BbXvvkF0KSnp2LWH59WKxbMEAtE+ taQgC+n2IGcs5kSu6ivHX9TWRClGusftuC3ngD0OL9rSCq2Sjr4MqnPUHpv+YKMN4bgb dRGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293046; x=1691897846; 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=d6Zi+aoJ23N/H+GWaJuCJ5CRje/J5FIcA9M9f2WcivTA32UzoK5NyG/L5Ni3fjbQAc eiF+YKQBBbypaKgQUpcBixNE6ThhvhhpFU0aFBuetnubO+kvRP4brQVB8B3lX2egSHJp 7NC78B8E/z+uCiFopNhbXQ6yNLcChfCl00bdhAya9nwq8OB7LkQxkmkEDNB3HN7YLSqV lRfTPr4MBqmtgLpJCpF7TTB+K1/FjrERz6O0xRVm9B/SiXMjga95AWzC48cdc1oT+lOu G4pNzJg2Sbh7tVFgQmtgUMUxZIdwoGqjmdQiepvPykwah7GQBElxL/rf0+nAQU1+b7Gv KeLg== X-Gm-Message-State: AOJu0YwVcCuW+5bV/CeVM14JKWmFL6XxITPQuucirWcQQWSQX99/TObM NoroezqVvgkeaHPTAJ4k6Tc5WIcweLgs6wx8aQs= X-Received: by 2002:a17:90a:4f4a:b0:268:b0b:a084 with SMTP id w10-20020a17090a4f4a00b002680b0ba084mr5596892pjl.46.1691293046291; Sat, 05 Aug 2023 20:37:26 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 12/24] bsd-user: Remove last_brk Date: Sat, 5 Aug 2023 20:37:03 -0700 Message-Id: <20230806033715.244648-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org This variable is unused. Signed-off-by: Richard Henderson --- bsd-user/qemu.h | 1 - bsd-user/mmap.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index edf9602f9b..8f2d6a3c78 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -232,7 +232,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, abi_ulong new_addr); int target_msync(abi_ulong start, abi_ulong len, int flags); -extern unsigned long last_brk; extern abi_ulong mmap_next_start; abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size); void TSA_NO_TSA mmap_fork_start(void); diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index b62a69bd07..8e148a2ea3 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -214,8 +214,6 @@ static int mmap_frag(abi_ulong real_start, #endif abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; -unsigned long last_brk; - /* * Subroutine of mmap_find_vma, used when we have pre-allocated a chunk of guest * address space. From patchwork Sun Aug 6 03:37:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710873 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826160rwb; Sat, 5 Aug 2023 20:39:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFSq5JqFkd9+v72UOsplnmO9jHVXKMUN7KI9vmAQSc2BtiUGuAAaKgLXonz0QSP0I/OCwrE X-Received: by 2002:a05:622a:64a:b0:40f:caca:8c33 with SMTP id a10-20020a05622a064a00b0040fcaca8c33mr7070488qtb.63.1691293151380; Sat, 05 Aug 2023 20:39:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293151; cv=none; d=google.com; s=arc-20160816; b=dd3cKYhsoHxeCDDPF0cMMhKEfZ9KJLdV4CqyhRik6nHDU5Q9KMJm1qf73jWyqBRXsq Ee5eLjskFijkUYZSY5Eyb2X+vv0q5qCfyxY85AWbbbzrCZaJ5SHbrU1sYf1TDznZ2o4Y ihobmZu+LXAEMXr3VvF7W9Llsqm4HtrMpPqPhkin/ZazhtP9K5lXImCyARHqsJpx4BoX SAryfzz97X3zCeG3cBKRKLXLspCZUBsYJFXrvP8qsLg6m61DvP8FRYtxi5LtMeRUBEo4 vktS7uHAdCHNJK3uaQYzG0q0RBS+wU5NCS2nTVH9WDcUQHgXkZHYt1X7OZQNSMpY//xk rkZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=esXvpi4eaSEXYu7hbvu9VsTfQefHdQqF7XtT9IOgTiM=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=NVdn1Dlx3ZyQSFZk+AWN23+Pt8VKfG4nZ8rkyp+hCZmoDBDQLELpCbcU0AfZTOqOLn 9EErEX75uJ6Oj6nO8PJ0tWJwMY8bIZSEN4880DfJRtxSte/xqIG+mi4V2aFDMdomShrR lksXXV1RnTIsxDtR8c2JIfgA/LUvmdLiwzCl7J+YaNH9+tkzLRZnbUka48nxvsC9NCiE DUEpnWHYG3neNAbYxEYfECE5K7yRAGetexj7PfijnkmMdmR+N9sR/iixbVbB8zoh0vkn HFAOdQqbS4kMMB7IC36J6YIfJ3/mm+6EnS6+kd9UklLoBdPDLZLWmlm4vaNQhN4tkFVi IvQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ohQkimh5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g5-20020ac87f45000000b004055a1d7c1dsi3315337qtk.187.2023.08.05.20.39.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:39:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ohQkimh5; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUaB-0003gB-9f; Sat, 05 Aug 2023 23:37:31 -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 1qSUaA-0003g2-2v for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:30 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUa8-0007Yp-G8 for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:29 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1bc3d94d40fso30158215ad.3 for ; Sat, 05 Aug 2023 20:37:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293047; x=1691897847; 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=ohQkimh57o+3PKRomccxlomjCdTC6totXVlv6tBnj8BvfSwzF2il2G/KD6W9RCNK9q iI2/Itua2PKXspsBthWC/FzgVeCd7naWWN1Um72XQjTn+fb0DSyJRdAMV1C3QO9wbTny oL+kHdZ657fMLk3Pn87yuaILm4LxtpJCWckGP3uzZzN9NTZG5lZkLQLsGxURtHarLQ/R L39cNlZW+KRrsNn0c0hyXfU5h1blMXSGWTpN9ePM5JqDD1bsTi0I4P9vR9I5TmrrCGJ+ 3udYT5BzZlHEvwPZxf5AeAl8UardeaBPdwGAmjyzHzAFQf4dw+PyC4WnAEw7Wr/A2Kmh J3Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293047; x=1691897847; 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=X5bS+gniVvq4r1kg5C92slDO6tJ6PneJc4kDU2B0WTXQ7bmHXUGlCf3KLqUtJ0YkSq IRx+8ht96lKrpff6ttkrCKuFJV8bsi6OxRXIfg8A/7JvZ8mEZjoX/A1eCmeAaTH/BKe9 4P3ReO40ITF4nxWb+3R56KbIUj7PM8axwsxS3Pn8CpAZMfRWfRGVPHw6QiO3RgkU+Y1m B8i6BzPhVkJR7PL8HvO1mVslDE+CR1VorJTIFLtFiS+YyWy/dqrqS8P0FKrQy4Q68Lav GaAvI+Kf9Pf28GuPAaCSwT1pcQrTMqmJNis2JSRHrPUFtEvK8KYl6wxYYrQhIx40ns0o 0Frg== X-Gm-Message-State: AOJu0YwMKapJH3mbkCU0ZomNxFUcgk9qqzod8OF+Sb/of/kd2SLJ+4uN C9yacnMhX7nRRqMgJ6uW/WEgm6qQ1u7RDdeC2kQ= X-Received: by 2002:a17:902:db10:b0:1b8:b41a:d4be with SMTP id m16-20020a170902db1000b001b8b41ad4bemr8439770plx.10.1691293046944; Sat, 05 Aug 2023 20:37:26 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PULL 13/24] linux-user: Adjust task_unmapped_base for reserved_va Date: Sat, 5 Aug 2023 20:37:04 -0700 Message-Id: <20230806033715.244648-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Ensure that the chosen values for mmap_next_start and task_unmapped_base are within the guest address space. Tested-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/user-mmap.h | 18 +++++++++++++++++- linux-user/main.c | 28 ++++++++++++++++++++++++++++ linux-user/mmap.c | 18 +++--------------- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index 7265c2c116..fd456e024e 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -18,6 +18,23 @@ #ifndef LINUX_USER_USER_MMAP_H #define LINUX_USER_USER_MMAP_H +#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 +#ifdef TARGET_AARCH64 +# define TASK_UNMAPPED_BASE 0x5500000000 +#else +# define TASK_UNMAPPED_BASE (1ul << 38) +#endif +#else +#ifdef TARGET_HPPA +# define TASK_UNMAPPED_BASE 0xfa000000 +#else +# define TASK_UNMAPPED_BASE 0x40000000 +#endif +#endif + +extern abi_ulong task_unmapped_base; +extern abi_ulong mmap_next_start; + int target_mprotect(abi_ulong start, abi_ulong len, int prot); abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, int flags, int fd, off_t offset); @@ -26,7 +43,6 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size, abi_ulong new_size, unsigned long flags, abi_ulong new_addr); abi_long target_madvise(abi_ulong start, abi_ulong len_in, int advice); -extern abi_ulong mmap_next_start; abi_ulong mmap_find_vma(abi_ulong, abi_ulong, abi_ulong); void mmap_fork_start(void); void mmap_fork_end(int child); diff --git a/linux-user/main.c b/linux-user/main.c index dba67ffa36..7ba7039988 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -821,6 +821,34 @@ int main(int argc, char **argv, char **envp) reserved_va = max_reserved_va; } + /* + * Temporarily disable + * "comparison is always false due to limited range of data type" + * due to comparison between (possible) uint64_t and uintptr_t. + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wtype-limits" + + /* + * Select an initial value for task_unmapped_base that is in range. + */ + if (reserved_va) { + if (TASK_UNMAPPED_BASE < reserved_va) { + task_unmapped_base = TASK_UNMAPPED_BASE; + } else { + /* The most common default formula is TASK_SIZE / 3. */ + task_unmapped_base = TARGET_PAGE_ALIGN(reserved_va / 3); + } + } else if (TASK_UNMAPPED_BASE < UINTPTR_MAX) { + task_unmapped_base = TASK_UNMAPPED_BASE; + } else { + /* 32-bit host: pick something medium size. */ + task_unmapped_base = 0x10000000; + } + mmap_next_start = task_unmapped_base; + +#pragma GCC diagnostic pop + { Error *err = NULL; if (seed_optarg != NULL) { diff --git a/linux-user/mmap.c b/linux-user/mmap.c index eb04fab8ab..84436d45c8 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -299,20 +299,8 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, return true; } -#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 -#ifdef TARGET_AARCH64 -# define TASK_UNMAPPED_BASE 0x5500000000 -#else -# define TASK_UNMAPPED_BASE (1ul << 38) -#endif -#else -#ifdef TARGET_HPPA -# define TASK_UNMAPPED_BASE 0xfa000000 -#else -# define TASK_UNMAPPED_BASE 0x40000000 -#endif -#endif -abi_ulong mmap_next_start = TASK_UNMAPPED_BASE; +abi_ulong task_unmapped_base; +abi_ulong mmap_next_start; /* * Subroutine of mmap_find_vma, used when we have pre-allocated @@ -391,7 +379,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong align) if ((addr & (align - 1)) == 0) { /* Success. */ - if (start == mmap_next_start && addr >= TASK_UNMAPPED_BASE) { + if (start == mmap_next_start && addr >= task_unmapped_base) { mmap_next_start = addr + size; } return addr; From patchwork Sun Aug 6 03:37:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710880 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826445rwb; Sat, 5 Aug 2023 20:40:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF5iFv93dzL/025QCLdqiOS5urUuDxOJFxJKLnEqepWj36rft8wTFXFYVi9TktwHZuVoGiw X-Received: by 2002:a0c:9d04:0:b0:63c:eb1e:e004 with SMTP id m4-20020a0c9d04000000b0063ceb1ee004mr5509823qvf.3.1691293216998; Sat, 05 Aug 2023 20:40:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293216; cv=none; d=google.com; s=arc-20160816; b=WVA68H98fEka8gon9CcIIw4nDiMcCeN8XLF+hscVFpME5kpb/gomvLIKniwWEPLJG+ 6MqkmX7+EdqZuJf+SZEZFlnlRslcMGc8FW/xzgJvnhJmuZ86SZvIAzcYzQ/UpP3foOkW RbWOgXMlkDWd8SwmCKryG0NNpx1MDukoYcJTUx7H+bdVI2UPOfikYWqJaZ7kBIVocjGE bgQEKs0fKruPyslKmQjTV7hc+jI59hq93kGGjGRLN7jtQXC2l7C1nbDX25GSX5yJwRsn 83byd0F8lNSI4LwAVHwHj/cb4bvJURDokpyBIiegD5L/wtJZO+UyKSUz2pw3O9p82HaQ F81w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nsfMjTlh4URCmzpsUVnlBQkKHMyACEHtsPPiByh/vaY=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=x66sWCBgTn2VrBD492xR/87ej8ZBw8PPpR2m1opdaGraxTRN9Z6APziEqjAd9lVhq6 azOMclZ8RffWw0VCMmwU6TzRKwruetAicCwFov9JP7uCBNsiBL2paUTKqCsJKT61WfSX WDeWakmG9D8j5ulP6tDEvjbTY/ZJ2GUFjbZ2am5AsFlbnaV4rJt1fpzE9+g7K9LOPw6L 6RfTqcnwUgz3Q1q56xu+ooBE53y65jbnb9nuQ9sDwDiKkUEa1IGzvuuAJi1PneLMBP5i n9NmSu+2vUkuCf1WfRvSPlKsGRmpNDgWUOUVDL3PuTuq1J77MXC6gyiEhHf9xbNsB4aF 3zKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rz3T5e2v; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t26-20020a0cb71a000000b0063c70525966si3372155qvd.176.2023.08.05.20.40.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:40:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Rz3T5e2v; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUaC-0003ge-WC; Sat, 05 Aug 2023 23:37:33 -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 1qSUaB-0003gC-9T for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:31 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUa9-0007Z3-4b for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:31 -0400 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-269304c135aso1102814a91.3 for ; Sat, 05 Aug 2023 20:37:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293048; x=1691897848; 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=Rz3T5e2v2nbbqXKo3BsIP4pu3qMicGAWNZk0JHBqyIR6QNwyqsiwvdVPRjPnq/VLIu bvx66ZHhixeIMYBoGZE2pV6mWV3sCpfVR42Qig6ZYgB81mi5ceMfIk2y6DaAbeRyRpnf rhRTkvCxCXkg2UyUSX1o/mmIuvWHf3KoxtkJjk3UIOY6L0Wdv+b1ckIKjHK78i2TAB77 jvP2YzkgtXmxmHc64/zzyu6ri1RKfNhcQCw6v7hFF0fSfBq0qZ0KaO3AKkRU+MO6isF8 6KIojaQRHsdb4o4YxrqhWcZkNV2YuXA+mbUXlHK7c6kPDnM2pDxhhGe/yDWhzt3LHDyz U+mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293048; x=1691897848; 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=Lr+LP5KmRw/UoiOGdh3dClsFn8XL96e46HYfEp6ocEhtJA9Ji9r/yeCruG67VDtJ/2 KeBrC40Y5smO525kNeg/NG5ML11YfnT9Bzo0j0HkcrOwA2u+AuQMcyeRxhQlpDBVFRvF N4B6lJ7a0uePw0QLcmwQ0LiWiGcEIHuGL4uaQOYxLiqDoTwH1ND0g4BQS0O5KALsH5PL 0k/8o9UVTyS4dSYWZfuCd5lGq92r+7Udi3wMTIpqB+xK0+YO4/t/J3yISvDePmGIUs0k FM2Mld00n1IJ8X2pro9VfZK3xh1z7bpjz4prGhoWHW5qGxNjCZzJH4RPfKx2S1jihk7G yiLw== X-Gm-Message-State: AOJu0YzspagsT2YOShVWqiDUgr+6+3uUTPMlrF+qEDa1gxS0MruymNHW Tb1SqLGka+ZN32bD+03QsEXC0u2uDx45VsV7Y+Y= X-Received: by 2002:a17:90a:bc92:b0:268:3582:a6be with SMTP id x18-20020a17090abc9200b002683582a6bemr5735572pjr.33.1691293047719; Sat, 05 Aug 2023 20:37:27 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PULL 14/24] linux-user: Define TASK_UNMAPPED_BASE in $guest/target_mman.h Date: Sat, 5 Aug 2023 20:37:05 -0700 Message-Id: <20230806033715.244648-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Provide default values that are as close as possible to the values used by the guest's kernel. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/aarch64/target_mman.h | 10 ++++++++++ linux-user/alpha/target_mman.h | 8 ++++++++ linux-user/arm/target_mman.h | 8 ++++++++ linux-user/cris/target_mman.h | 9 +++++++++ linux-user/hexagon/target_mman.h | 10 ++++++++++ linux-user/hppa/target_mman.h | 3 +++ linux-user/i386/target_mman.h | 13 +++++++++++++ linux-user/loongarch64/target_mman.h | 8 ++++++++ linux-user/m68k/target_mman.h | 3 +++ linux-user/microblaze/target_mman.h | 8 ++++++++ linux-user/mips/target_mman.h | 7 +++++++ linux-user/nios2/target_mman.h | 7 +++++++ linux-user/openrisc/target_mman.h | 7 +++++++ linux-user/ppc/target_mman.h | 13 +++++++++++++ linux-user/riscv/target_mman.h | 7 +++++++ linux-user/s390x/target_mman.h | 10 ++++++++++ linux-user/sh4/target_mman.h | 4 ++++ linux-user/sparc/target_mman.h | 14 ++++++++++++++ linux-user/user-mmap.h | 14 -------------- linux-user/x86_64/target_mman.h | 12 ++++++++++++ linux-user/xtensa/target_mman.h | 6 ++++++ 21 files changed, 167 insertions(+), 14 deletions(-) diff --git a/linux-user/aarch64/target_mman.h b/linux-user/aarch64/target_mman.h index f721295fe1..4d3eecfb26 100644 --- a/linux-user/aarch64/target_mman.h +++ b/linux-user/aarch64/target_mman.h @@ -4,6 +4,16 @@ #define TARGET_PROT_BTI 0x10 #define TARGET_PROT_MTE 0x20 +/* + * arch/arm64/include/asm/processor.h: + * + * TASK_UNMAPPED_BASE DEFAULT_MAP_WINDOW / 4 + * DEFAULT_MAP_WINDOW DEFAULT_MAP_WINDOW_64 + * DEFAULT_MAP_WINDOW_64 UL(1) << VA_BITS_MIN + * VA_BITS_MIN 48 (unless explicitly configured smaller) + */ +#define TASK_UNMAPPED_BASE (1ull << (48 - 2)) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/alpha/target_mman.h b/linux-user/alpha/target_mman.h index 6bb03e7336..c90b493711 100644 --- a/linux-user/alpha/target_mman.h +++ b/linux-user/alpha/target_mman.h @@ -20,6 +20,14 @@ #define TARGET_MS_SYNC 2 #define TARGET_MS_INVALIDATE 4 +/* + * arch/alpha/include/asm/processor.h: + * + * TASK_UNMAPPED_BASE TASK_SIZE / 2 + * TASK_SIZE 0x40000000000UL + */ +#define TASK_UNMAPPED_BASE 0x20000000000ull + #include "../generic/target_mman.h" #endif diff --git a/linux-user/arm/target_mman.h b/linux-user/arm/target_mman.h index e7ba6070fe..76275b2c7e 100644 --- a/linux-user/arm/target_mman.h +++ b/linux-user/arm/target_mman.h @@ -1 +1,9 @@ +/* + * arch/arm/include/asm/memory.h + * TASK_UNMAPPED_BASE ALIGN(TASK_SIZE / 3, SZ_16M) + * TASK_SIZE CONFIG_PAGE_OFFSET + * CONFIG_PAGE_OFFSET 0xC0000000 (default in Kconfig) + */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" diff --git a/linux-user/cris/target_mman.h b/linux-user/cris/target_mman.h index e7ba6070fe..9df7b1eda5 100644 --- a/linux-user/cris/target_mman.h +++ b/linux-user/cris/target_mman.h @@ -1 +1,10 @@ +/* + * arch/cris/include/asm/processor.h: + * TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3)) + * + * arch/cris/include/arch-v32/arch/processor.h + * TASK_SIZE 0xb0000000 + */ +#define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0xb0000000 / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/hexagon/target_mman.h b/linux-user/hexagon/target_mman.h index e7ba6070fe..c5ae336e07 100644 --- a/linux-user/hexagon/target_mman.h +++ b/linux-user/hexagon/target_mman.h @@ -1 +1,11 @@ +/* + * arch/hexgon/include/asm/processor.h + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + * + * arch/hexagon/include/asm/mem-layout.h + * TASK_SIZE PAGE_OFFSET + * PAGE_OFFSET 0xc0000000 + */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" diff --git a/linux-user/hppa/target_mman.h b/linux-user/hppa/target_mman.h index 97f87d042a..6459e7dbdd 100644 --- a/linux-user/hppa/target_mman.h +++ b/linux-user/hppa/target_mman.h @@ -24,6 +24,9 @@ #define TARGET_MS_ASYNC 2 #define TARGET_MS_INVALIDATE 4 +/* arch/parisc/include/asm/processor.h: DEFAULT_MAP_BASE32 */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" #endif diff --git a/linux-user/i386/target_mman.h b/linux-user/i386/target_mman.h index e7ba6070fe..cc3382007f 100644 --- a/linux-user/i386/target_mman.h +++ b/linux-user/i386/target_mman.h @@ -1 +1,14 @@ +/* + * arch/x86/include/asm/processor.h: + * TASK_UNMAPPED_BASE __TASK_UNMAPPED_BASE(TASK_SIZE_LOW) + * __TASK_UNMAPPED_BASE(S) PAGE_ALIGN(S / 3) + * + * arch/x86/include/asm/page_32_types.h: + * TASK_SIZE_LOW TASK_SIZE + * TASK_SIZE __PAGE_OFFSET + * __PAGE_OFFSET CONFIG_PAGE_OFFSET + * CONFIG_PAGE_OFFSET 0xc0000000 (default in Kconfig) + */ +#define TASK_UNMAPPED_BASE 0x40000000 + #include "../generic/target_mman.h" diff --git a/linux-user/loongarch64/target_mman.h b/linux-user/loongarch64/target_mman.h index e7ba6070fe..d70e44d44c 100644 --- a/linux-user/loongarch64/target_mman.h +++ b/linux-user/loongarch64/target_mman.h @@ -1 +1,9 @@ +/* + * arch/loongarch/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + * TASK_SIZE64 0x1UL << (... ? VA_BITS : ...) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/m68k/target_mman.h b/linux-user/m68k/target_mman.h index e7ba6070fe..d3eceb663b 100644 --- a/linux-user/m68k/target_mman.h +++ b/linux-user/m68k/target_mman.h @@ -1 +1,4 @@ +/* arch/m68k/include/asm/processor.h */ +#define TASK_UNMAPPED_BASE 0xC0000000 + #include "../generic/target_mman.h" diff --git a/linux-user/microblaze/target_mman.h b/linux-user/microblaze/target_mman.h index e7ba6070fe..ffee869db4 100644 --- a/linux-user/microblaze/target_mman.h +++ b/linux-user/microblaze/target_mman.h @@ -1 +1,9 @@ +/* + * arch/microblaze/include/asm/processor.h: + * TASK_UNMAPPED_BASE (TASK_SIZE / 8 * 3) + * TASK_SIZE CONFIG_KERNEL_START + * CONFIG_KERNEL_START 0xc0000000 (default in Kconfig) + */ +#define TASK_UNMAPPED_BASE 0x48000000 + #include "../generic/target_mman.h" diff --git a/linux-user/mips/target_mman.h b/linux-user/mips/target_mman.h index e97694aa4e..fe1eec2d0b 100644 --- a/linux-user/mips/target_mman.h +++ b/linux-user/mips/target_mman.h @@ -14,6 +14,13 @@ #define TARGET_MAP_STACK 0x40000 #define TARGET_MAP_HUGETLB 0x80000 +/* + * arch/mips/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/nios2/target_mman.h b/linux-user/nios2/target_mman.h index e7ba6070fe..ce18f4f871 100644 --- a/linux-user/nios2/target_mman.h +++ b/linux-user/nios2/target_mman.h @@ -1 +1,8 @@ +/* + * arch/nios2/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + * TASK_SIZE 0x7FFF0000UL + */ +#define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0x7FFF0000 / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/openrisc/target_mman.h b/linux-user/openrisc/target_mman.h index e7ba6070fe..f1aaad809d 100644 --- a/linux-user/openrisc/target_mman.h +++ b/linux-user/openrisc/target_mman.h @@ -1 +1,8 @@ +/* + * arch/openrisc/include/asm/processor.h: + * TASK_UNMAPPED_BASE (TASK_SIZE / 8 * 3) + * TASK_SIZE (0x80000000UL) + */ +#define TASK_UNMAPPED_BASE 0x30000000 + #include "../generic/target_mman.h" diff --git a/linux-user/ppc/target_mman.h b/linux-user/ppc/target_mman.h index 67cc218f2e..04f99c6077 100644 --- a/linux-user/ppc/target_mman.h +++ b/linux-user/ppc/target_mman.h @@ -4,6 +4,19 @@ #define TARGET_MAP_NORESERVE 0x40 #define TARGET_MAP_LOCKED 0x80 +/* + * arch/powerpc/include/asm/task_size_64.h + * TASK_UNMAPPED_BASE_USER32 (PAGE_ALIGN(TASK_SIZE_USER32 / 4)) + * TASK_UNMAPPED_BASE_USER64 (PAGE_ALIGN(DEFAULT_MAP_WINDOW_USER64 / 4)) + * TASK_SIZE_USER32 (0x0000000100000000UL - (1 * PAGE_SIZE)) + * DEFAULT_MAP_WINDOW_USER64 TASK_SIZE_64TB (with 4k pages) + */ +#ifdef TARGET_PPC64 +#define TASK_UNMAPPED_BASE 0x0000100000000000ull +#else +#define TASK_UNMAPPED_BASE 0x40000000 +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/riscv/target_mman.h b/linux-user/riscv/target_mman.h index e7ba6070fe..0f06dadbd4 100644 --- a/linux-user/riscv/target_mman.h +++ b/linux-user/riscv/target_mman.h @@ -1 +1,8 @@ +/* + * arch/loongarch/include/asm/processor.h: + * TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE / 3) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/s390x/target_mman.h b/linux-user/s390x/target_mman.h index e7ba6070fe..40d149b329 100644 --- a/linux-user/s390x/target_mman.h +++ b/linux-user/s390x/target_mman.h @@ -1 +1,11 @@ +/* + * arch/s390/include/asm/processor.h: + * TASK_UNMAPPED_BASE (... : (_REGION2_SIZE >> 1)) + * + * arch/s390/include/asm/pgtable.h: + * _REGION2_SIZE (1UL << _REGION2_SHIFT) + * _REGION2_SHIFT 42 + */ +#define TASK_UNMAPPED_BASE (1ull << 41) + #include "../generic/target_mman.h" diff --git a/linux-user/sh4/target_mman.h b/linux-user/sh4/target_mman.h index e7ba6070fe..bbbc223398 100644 --- a/linux-user/sh4/target_mman.h +++ b/linux-user/sh4/target_mman.h @@ -1 +1,5 @@ +/* arch/sh/include/asm/processor_32.h */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/sparc/target_mman.h b/linux-user/sparc/target_mman.h index 9bad99c852..692ebf9dd7 100644 --- a/linux-user/sparc/target_mman.h +++ b/linux-user/sparc/target_mman.h @@ -5,6 +5,20 @@ #define TARGET_MAP_LOCKED 0x100 #define TARGET_MAP_GROWSDOWN 0x0200 +/* + * arch/sparc/include/asm/page_64.h: + * TASK_UNMAPPED_BASE (test_thread_flag(TIF_32BIT) ? \ + * _AC(0x0000000070000000,UL) : \ + * VA_EXCLUDE_END) + * But VA_EXCLUDE_END is > 0xffff800000000000UL which doesn't work + * in userland emulation. + */ +#ifdef TARGET_ABI32 +#define TASK_UNMAPPED_BASE 0x70000000 +#else +#define TASK_UNMAPPED_BASE (1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 2)) +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index fd456e024e..bae49059e0 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -18,20 +18,6 @@ #ifndef LINUX_USER_USER_MMAP_H #define LINUX_USER_USER_MMAP_H -#if HOST_LONG_BITS == 64 && TARGET_ABI_BITS == 64 -#ifdef TARGET_AARCH64 -# define TASK_UNMAPPED_BASE 0x5500000000 -#else -# define TASK_UNMAPPED_BASE (1ul << 38) -#endif -#else -#ifdef TARGET_HPPA -# define TASK_UNMAPPED_BASE 0xfa000000 -#else -# define TASK_UNMAPPED_BASE 0x40000000 -#endif -#endif - extern abi_ulong task_unmapped_base; extern abi_ulong mmap_next_start; diff --git a/linux-user/x86_64/target_mman.h b/linux-user/x86_64/target_mman.h index e7ba6070fe..f9ff652b37 100644 --- a/linux-user/x86_64/target_mman.h +++ b/linux-user/x86_64/target_mman.h @@ -1 +1,13 @@ +/* + * arch/x86/include/asm/processor.h: + * TASK_UNMAPPED_BASE __TASK_UNMAPPED_BASE(TASK_SIZE_LOW) + * __TASK_UNMAPPED_BASE(S) PAGE_ALIGN(S / 3) + * + * arch/x86/include/asm/page_64_types.h: + * TASK_SIZE_LOW DEFAULT_MAP_WINDOW + * DEFAULT_MAP_WINDOW ((1UL << 47) - PAGE_SIZE) + */ +#define TASK_UNMAPPED_BASE \ + TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" diff --git a/linux-user/xtensa/target_mman.h b/linux-user/xtensa/target_mman.h index 3933771b5b..c4f671adb7 100644 --- a/linux-user/xtensa/target_mman.h +++ b/linux-user/xtensa/target_mman.h @@ -14,6 +14,12 @@ #define TARGET_MAP_STACK 0x40000 #define TARGET_MAP_HUGETLB 0x80000 +/* + * arch/xtensa/include/asm/processor.h: + * TASK_UNMAPPED_BASE (TASK_SIZE / 2) + */ +#define TASK_UNMAPPED_BASE (1u << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) + #include "../generic/target_mman.h" #endif From patchwork Sun Aug 6 03:37:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710887 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp827310rwb; Sat, 5 Aug 2023 20:43:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdM8Ks6gifpyWDUTiD+5Zx34kjBJqJ2XWtFuSXGHsvWzNm1rVHLcHdQtvJbPzKUj7gyYev X-Received: by 2002:a0c:e453:0:b0:63f:7d58:669c with SMTP id d19-20020a0ce453000000b0063f7d58669cmr2456431qvm.61.1691293426714; Sat, 05 Aug 2023 20:43:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293426; cv=none; d=google.com; s=arc-20160816; b=tSH0FfVx7IadrKGW/wk64eDu05QeN5f1+Tej03c7MiQgRdGyuYuowBe+YphRy01lya e4eRj5QoDLhBOpPwvkIN52ormzGCPMZ4vR/bgGYjufjtyzdyxaTj3KrLeRceDR3geLFW maQwgbojfQWoc3CFw1vIZogU1OwSO1u08ZZFKJ8xzFdpEahVoBRx4Dwe5jNCY77OjHvT 6vbRpdOmNJHYnAEy4DiH9FhWOG3j1NH4UQfdbGGuLHbn/5utQLayvlmQ4WN2uOh2RCW7 uJz4aVW00ZRB+5EBR0ou1j02ze1KNfG9BgQQhhY4hYO6rkifVH4Sud8IB+Yy+Ysy1zKn IBjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Xi2nnTJzHZgHa81d23KxFW8Q4gCAsLnkTLrg8o9pfyQ=; fh=nKwyeXx8rt8hF214OSFP+HjBpDto8utNxLoZSNqK/Bc=; b=VTv+3lj2tUJYAOZ+nvPTqXN1a5ztAho9JQpTOgdPDe4Y75kU2GxR1g6QIDJpHAA4Qp uupOnovcJy0hlG5II1QXWWrlxxksG1EAw/xrYR9tBSM/F9XPFJXrLBCvCQvm91GRlVhr vqgdwgpFZjKtAgY8myt/F4hPnxuf8YSqf5zDtBaeVnk6bbQWO5iIINMgP0p+Kocpd2wp n3UGG4m+CcfYPLsDyV1Xofd1ZYgwG2xIRkBFg7IkxsTKRaWMYlyPz0iiVsgvg4OOGSb0 5coippHJljII/PPW1KTCQ7jZpln+8umbqkKMqsx/LWs+l0qBYdr2L79o5ejXT7QHORAJ Q2tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dtQQz79t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i2-20020a0cab42000000b0063d4cfb4d52si3236051qvb.430.2023.08.05.20.43.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:43:46 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dtQQz79t; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUaD-0003gf-49; Sat, 05 Aug 2023 23:37:33 -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 1qSUaB-0003gN-Sz for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:31 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUa9-0007ZR-Qk for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:31 -0400 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-267fc1d776eso1814817a91.2 for ; Sat, 05 Aug 2023 20:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293048; x=1691897848; 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=dtQQz79talruJZEYwqDK5lLnvVk2PTr3YmoetA4z2LL0kLalNPVagsEtktZrQBrns4 5mtY3AUq1rUrnfd+m2Jt7lTHiy0TI1BsM/C7ooD6JaRDWNwXG4fnxq2yi6IpGcczgpiC 1t2HPWE9tAj9eXHziwP4QWqMWdaEfGCgc20mWVaRWtLeJMXsWp0r7eF7T/dkEWkLcfqL SgEDkaJ6xqCSG53D1mXYgzv7l0O/7hhJCZeuzfKwA+jwy7/zWfiX+qwtTSJnXzdiDHXh wpasdDUyj8Zai6SUGbWpBhMMSdyGIiEuzUvDCST9xtluoA95FDpoKzJYesnQiQEnQEd+ 7kjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293048; x=1691897848; 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=X8EFaHpdhTI942dpeyyPWXrq7+r3lL9kMCv6oj77AUeKygQt43IbdSDf98V+FqsbnE woiHua2hE7DE7W2Qj0LBN0zZk9O+AaKgVg1RUbDSiT1S57QAnciEZ2sqoQyF3iKd20+c /n3fdu6spGi2ub/MmLzGbQcLrcYbpmONE6YeIlIA86taRVjEj8UDa5M0tHnDrlQA7VXJ Y3UEdD5p5wrbn+gNZAhbPxgsW7CGd+IIeV00lQTUkZ7EonWPZoK/m5OyXkexm0jfhiiD uZCeMybu5yIewOP0KR+jBjNU9TLEBjmChQjou3sKhb69MVvuo1cnWiY+7UaR8H+v3qJ1 YSWg== X-Gm-Message-State: AOJu0Yz6yzw8ZU0kWfsU7+aUEAsWVprPOcaNycyCYjFdwsrTdv2JTE8T a1JkTMd1paYOLemHrj2YxWoglvSpux/s/ArCTAw= X-Received: by 2002:a17:90a:a04:b0:267:faba:705 with SMTP id o4-20020a17090a0a0400b00267faba0705mr4235715pjo.10.1691293048659; Sat, 05 Aug 2023 20:37:28 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller Subject: [PULL 15/24] linux-user: Define ELF_ET_DYN_BASE in $guest/target_mman.h Date: Sat, 5 Aug 2023 20:37:06 -0700 Message-Id: <20230806033715.244648-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Copy each guest kernel's default value, then bound it against reserved_va or the host address space. Tested-by: Helge Deller Reviewed-by: Helge Deller Signed-off-by: Richard Henderson --- linux-user/aarch64/target_mman.h | 3 +++ linux-user/alpha/target_mman.h | 3 +++ linux-user/arm/target_mman.h | 3 +++ linux-user/cris/target_mman.h | 3 +++ linux-user/hexagon/target_mman.h | 3 +++ linux-user/hppa/target_mman.h | 3 +++ linux-user/i386/target_mman.h | 3 +++ linux-user/loongarch64/target_mman.h | 3 +++ linux-user/m68k/target_mman.h | 2 ++ linux-user/microblaze/target_mman.h | 3 +++ linux-user/mips/target_mman.h | 3 +++ linux-user/nios2/target_mman.h | 3 +++ linux-user/openrisc/target_mman.h | 3 +++ linux-user/ppc/target_mman.h | 7 +++++++ linux-user/riscv/target_mman.h | 3 +++ linux-user/s390x/target_mman.h | 10 ++++++++++ linux-user/sh4/target_mman.h | 3 +++ linux-user/sparc/target_mman.h | 11 +++++++++++ linux-user/user-mmap.h | 1 + linux-user/x86_64/target_mman.h | 3 +++ linux-user/xtensa/target_mman.h | 4 ++++ linux-user/main.c | 15 +++++++++++++++ linux-user/mmap.c | 1 + 23 files changed, 96 insertions(+) diff --git a/linux-user/aarch64/target_mman.h b/linux-user/aarch64/target_mman.h index 4d3eecfb26..69ec5d5739 100644 --- a/linux-user/aarch64/target_mman.h +++ b/linux-user/aarch64/target_mman.h @@ -14,6 +14,9 @@ */ #define TASK_UNMAPPED_BASE (1ull << (48 - 2)) +/* arch/arm64/include/asm/elf.h */ +#define ELF_ET_DYN_BASE TARGET_PAGE_ALIGN((1ull << 48) / 3 * 2) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/alpha/target_mman.h b/linux-user/alpha/target_mman.h index c90b493711..8edfe2b88c 100644 --- a/linux-user/alpha/target_mman.h +++ b/linux-user/alpha/target_mman.h @@ -28,6 +28,9 @@ */ #define TASK_UNMAPPED_BASE 0x20000000000ull +/* arch/alpha/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/arm/target_mman.h b/linux-user/arm/target_mman.h index 76275b2c7e..51005da869 100644 --- a/linux-user/arm/target_mman.h +++ b/linux-user/arm/target_mman.h @@ -6,4 +6,7 @@ */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/arm/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x00400000 + #include "../generic/target_mman.h" diff --git a/linux-user/cris/target_mman.h b/linux-user/cris/target_mman.h index 9df7b1eda5..9ace8ac292 100644 --- a/linux-user/cris/target_mman.h +++ b/linux-user/cris/target_mman.h @@ -7,4 +7,7 @@ */ #define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0xb0000000 / 3) +/* arch/cris/include/uapi/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/hexagon/target_mman.h b/linux-user/hexagon/target_mman.h index c5ae336e07..e6b5e2ca36 100644 --- a/linux-user/hexagon/target_mman.h +++ b/linux-user/hexagon/target_mman.h @@ -8,4 +8,7 @@ */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/hexagon/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x08000000 + #include "../generic/target_mman.h" diff --git a/linux-user/hppa/target_mman.h b/linux-user/hppa/target_mman.h index 6459e7dbdd..ccda46e842 100644 --- a/linux-user/hppa/target_mman.h +++ b/linux-user/hppa/target_mman.h @@ -27,6 +27,9 @@ /* arch/parisc/include/asm/processor.h: DEFAULT_MAP_BASE32 */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/parisc/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/i386/target_mman.h b/linux-user/i386/target_mman.h index cc3382007f..e3b8e1eaa6 100644 --- a/linux-user/i386/target_mman.h +++ b/linux-user/i386/target_mman.h @@ -11,4 +11,7 @@ */ #define TASK_UNMAPPED_BASE 0x40000000 +/* arch/x86/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x00400000 + #include "../generic/target_mman.h" diff --git a/linux-user/loongarch64/target_mman.h b/linux-user/loongarch64/target_mman.h index d70e44d44c..8c2a3d5596 100644 --- a/linux-user/loongarch64/target_mman.h +++ b/linux-user/loongarch64/target_mman.h @@ -6,4 +6,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/loongarch/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/m68k/target_mman.h b/linux-user/m68k/target_mman.h index d3eceb663b..20cfe750c5 100644 --- a/linux-user/m68k/target_mman.h +++ b/linux-user/m68k/target_mman.h @@ -1,4 +1,6 @@ /* arch/m68k/include/asm/processor.h */ #define TASK_UNMAPPED_BASE 0xC0000000 +/* arch/m68k/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0xD0000000 #include "../generic/target_mman.h" diff --git a/linux-user/microblaze/target_mman.h b/linux-user/microblaze/target_mman.h index ffee869db4..6b3dd54f89 100644 --- a/linux-user/microblaze/target_mman.h +++ b/linux-user/microblaze/target_mman.h @@ -6,4 +6,7 @@ */ #define TASK_UNMAPPED_BASE 0x48000000 +/* arch/microblaze/include/uapi/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x08000000 + #include "../generic/target_mman.h" diff --git a/linux-user/mips/target_mman.h b/linux-user/mips/target_mman.h index fe1eec2d0b..b84fe1e8a8 100644 --- a/linux-user/mips/target_mman.h +++ b/linux-user/mips/target_mman.h @@ -21,6 +21,9 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/mips/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/nios2/target_mman.h b/linux-user/nios2/target_mman.h index ce18f4f871..ab16ad4f03 100644 --- a/linux-user/nios2/target_mman.h +++ b/linux-user/nios2/target_mman.h @@ -5,4 +5,7 @@ */ #define TASK_UNMAPPED_BASE TARGET_PAGE_ALIGN(0x7FFF0000 / 3) +/* arch/nios2/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0xD0000000 + #include "../generic/target_mman.h" diff --git a/linux-user/openrisc/target_mman.h b/linux-user/openrisc/target_mman.h index f1aaad809d..243c1d5f26 100644 --- a/linux-user/openrisc/target_mman.h +++ b/linux-user/openrisc/target_mman.h @@ -5,4 +5,7 @@ */ #define TASK_UNMAPPED_BASE 0x30000000 +/* arch/openrisc/include/asm/elf.h */ +#define ELF_ET_DYN_BASE 0x08000000 + #include "../generic/target_mman.h" diff --git a/linux-user/ppc/target_mman.h b/linux-user/ppc/target_mman.h index 04f99c6077..646d1ccae7 100644 --- a/linux-user/ppc/target_mman.h +++ b/linux-user/ppc/target_mman.h @@ -17,6 +17,13 @@ #define TASK_UNMAPPED_BASE 0x40000000 #endif +/* arch/powerpc/include/asm/elf.h */ +#ifdef TARGET_PPC64 +#define ELF_ET_DYN_BASE 0x100000000ull +#else +#define ELF_ET_DYN_BASE 0x000400000 +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/riscv/target_mman.h b/linux-user/riscv/target_mman.h index 0f06dadbd4..3049bcc67d 100644 --- a/linux-user/riscv/target_mman.h +++ b/linux-user/riscv/target_mman.h @@ -5,4 +5,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) / 3) +/* arch/riscv/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/s390x/target_mman.h b/linux-user/s390x/target_mman.h index 40d149b329..c82435e381 100644 --- a/linux-user/s390x/target_mman.h +++ b/linux-user/s390x/target_mman.h @@ -8,4 +8,14 @@ */ #define TASK_UNMAPPED_BASE (1ull << 41) +/* + * arch/s390/include/asm/elf.h: + * ELF_ET_DYN_BASE (STACK_TOP / 3 * 2) & ~((1UL << 32) - 1) + * + * arch/s390/include/asm/processor.h: + * STACK_TOP VDSO_LIMIT - VDSO_SIZE - PAGE_SIZE + * VDSO_LIMIT _REGION2_SIZE + */ +#define ELF_ET_DYN_BASE (((1ull << 42) / 3 * 2) & ~0xffffffffull) + #include "../generic/target_mman.h" diff --git a/linux-user/sh4/target_mman.h b/linux-user/sh4/target_mman.h index bbbc223398..dd9016081e 100644 --- a/linux-user/sh4/target_mman.h +++ b/linux-user/sh4/target_mman.h @@ -2,4 +2,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/sh/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/sparc/target_mman.h b/linux-user/sparc/target_mman.h index 692ebf9dd7..696ca73fe4 100644 --- a/linux-user/sparc/target_mman.h +++ b/linux-user/sparc/target_mman.h @@ -19,6 +19,17 @@ #define TASK_UNMAPPED_BASE (1ull << (TARGET_VIRT_ADDR_SPACE_BITS - 2)) #endif +/* + * arch/sparc/include/asm/elf_64.h + * Except that COMPAT_ELF_ET_DYN_BASE exactly matches TASK_UNMAPPED_BASE, + * so move it up a bit. + */ +#ifdef TARGET_ABI32 +#define ELF_ET_DYN_BASE 0x78000000 +#else +#define ELF_ET_DYN_BASE 0x0000010000000000ull +#endif + #include "../generic/target_mman.h" #endif diff --git a/linux-user/user-mmap.h b/linux-user/user-mmap.h index bae49059e0..5dd48a458d 100644 --- a/linux-user/user-mmap.h +++ b/linux-user/user-mmap.h @@ -20,6 +20,7 @@ extern abi_ulong task_unmapped_base; extern abi_ulong mmap_next_start; +extern abi_ulong elf_et_dyn_base; int target_mprotect(abi_ulong start, abi_ulong len, int prot); abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, diff --git a/linux-user/x86_64/target_mman.h b/linux-user/x86_64/target_mman.h index f9ff652b37..48fbf20b42 100644 --- a/linux-user/x86_64/target_mman.h +++ b/linux-user/x86_64/target_mman.h @@ -10,4 +10,7 @@ #define TASK_UNMAPPED_BASE \ TARGET_PAGE_ALIGN((1ull << TARGET_VIRT_ADDR_SPACE_BITS) / 3) +/* arch/x86/include/asm/elf.h */ +#define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE * 2) + #include "../generic/target_mman.h" diff --git a/linux-user/xtensa/target_mman.h b/linux-user/xtensa/target_mman.h index c4f671adb7..8fa6337a97 100644 --- a/linux-user/xtensa/target_mman.h +++ b/linux-user/xtensa/target_mman.h @@ -20,6 +20,10 @@ */ #define TASK_UNMAPPED_BASE (1u << (TARGET_VIRT_ADDR_SPACE_BITS - 1)) +/* arch/xtensa/include/asm/elf.h */ +#define ELF_ET_DYN_BASE \ + TARGET_PAGE_ALIGN((1u << TARGET_VIRT_ADDR_SPACE_BITS) / 3) + #include "../generic/target_mman.h" #endif diff --git a/linux-user/main.c b/linux-user/main.c index 7ba7039988..cb5e80612b 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -847,6 +847,21 @@ int main(int argc, char **argv, char **envp) } mmap_next_start = task_unmapped_base; + /* Similarly for elf_et_dyn_base. */ + if (reserved_va) { + if (ELF_ET_DYN_BASE < reserved_va) { + elf_et_dyn_base = ELF_ET_DYN_BASE; + } else { + /* The most common default formula is TASK_SIZE / 3 * 2. */ + elf_et_dyn_base = TARGET_PAGE_ALIGN(reserved_va / 3) * 2; + } + } else if (ELF_ET_DYN_BASE < UINTPTR_MAX) { + elf_et_dyn_base = ELF_ET_DYN_BASE; + } else { + /* 32-bit host: pick something medium size. */ + elf_et_dyn_base = 0x18000000; + } + #pragma GCC diagnostic pop { diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 84436d45c8..949c4090f3 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -301,6 +301,7 @@ static bool mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong last, abi_ulong task_unmapped_base; abi_ulong mmap_next_start; +abi_ulong elf_et_dyn_base; /* * Subroutine of mmap_find_vma, used when we have pre-allocated From patchwork Sun Aug 6 03:37:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710869 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826071rwb; Sat, 5 Aug 2023 20:38:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF3oWe1j2htxQ7tF7pNHnNPAzzCh9M1CgzIPpBLzi9kggXmFijDWhwONIg84m7vIZ9ymPPq X-Received: by 2002:a0d:d48f:0:b0:56d:2afa:5801 with SMTP id w137-20020a0dd48f000000b0056d2afa5801mr6996866ywd.46.1691293125733; Sat, 05 Aug 2023 20:38:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293125; cv=none; d=google.com; s=arc-20160816; b=Af8nxlKPztvINn15N76MxRE3cZ0NVq8TNWDHGck4zFE4d7FeNQ4Mwz4iRFx4XWNOaA yRfNgxdOSDyRRsN8uFA/H8+Y/eEhJeri6Iekbl9VVehRC21cVNphkRcTPTLwDiHRIBxt lzcrS550OUFhzL5gHZP5CaDY3DVk3OOP26c1oBSGqZ9QJB9I2AupZNToGqO/8MHagBWE gipkN1gWv85pHLkfglVv33DPGBHIDJ3WxbMl53eF/Mxjo7DmpAfeMV1FDFQRTV2HV6mJ VUj3x+hKgMw5MYxjVwm5nbKvq05NHs0Fo+iwbP15xddC2lUvj6/VF8aDHInib3bvSKwf +/tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LDzaMFTSuoNmnLh18AUGiF2g+chM/kwaFDD4OLCcPrg=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=vomPozctrgsg6DE89BvELws4YVtdKeVJ1N1yWapXTaiuwfUAvZFqVulBE2IjKCveH4 zq0c6hH2fs9QviUH2o7orsr21dSugyi0e2gkuhPUc/Jp+2A+vuO4H7UkgcpLJmkUsE2U 4AQhrFIBveGdHQnh4J3ig+txO7Ju4Js16bLch69BY4x1M8L+ig3U4HZ0qO2F9JjB1IXJ 2EIv1FGhyNTTgqNWc7KBJYp2tGIoojbN1NvZuqbalMh27L0aLbdH/rPFvLA2Gd5hBPw0 zbZ+SACM4o4G+hftx1PdqgN0B1pluCHTECaIKndq1ZTcewIlaA4P8PZ46vECr8b72Yfj dPOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Ca2j5s/B"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m8-20020a05620a290800b00767dcd66284si3365734qkp.260.2023.08.05.20.38.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:38:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Ca2j5s/B"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUaF-0003ii-S4; Sat, 05 Aug 2023 23:37:35 -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 1qSUaC-0003gV-CJ for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:32 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUaA-0007Zf-UJ for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:32 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-5645bbc82aaso2460846a12.2 for ; Sat, 05 Aug 2023 20:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293049; x=1691897849; 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=Ca2j5s/BFtOLCUKfMdbZy1xHU1VLWsUnkcnOuRkHvZaJt10Ar/8c/CS7zIkznYQLUt wcvYKUbvv0fUXa/i144iNeKbhky3wX8vwoXl7D5oAdfh0MoGK7T9QMVkVHZUYapJOzlh TeP5TVAFjJ+bs1pihN4NyjOCmcB3+Os2VIbAABHuqntzP05B2YylYI4/qth57FO70yAR 9g3JQOtIdi/DTH3epXm4D3e/ptBlntamVnSdP8Z/l7gCmIVAzfC9LoIPXV9Mc8xCqUo0 GU4vpz61YxzYBKC8L3E1dAgCfQJnqUYHRLch292/gBcuAXX+uLykPzyHSunn8hAill3d mkVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293049; x=1691897849; 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=LOjQO4iVkgSmfb4rqJHlHjMfMsa345OHhV85dj4VsSnGC4fJB9oZ2VsWjZ4CQ5EMEl wSE2t+hvUTxeVX/dIOkCnHnLBlO/VWkwX6QOR8lqPq4vAPP0excRrZkhsjw9GwxHQRpJ zh+n0PFVSdB2/2K26efcOycG3D/HYUcoGg8QvxbXp3VDbdg9BlxmZNyWGvQO4Hct6R5O 1m+/EZOO5AYFx/2kisMjW0+P7gkr0fAbxQThYTroaBOPoDe4u86ewsv92Febhumc2R1t Ex/QR9A3Bu9tuTm5kXFC2hVrB+qTzdAXwM1HGi6aH0b9hLmCx8sCeP6LnBS1k4QjvbWw v9oQ== X-Gm-Message-State: AOJu0YwQETV7+LUjPIvAtJFg3h7vKqUxBfnLnpZF/EpkWm6dxOgna2xY D3pyQZidPGm29HberEyE7DtohaF5Bc+3gFa+AAg= X-Received: by 2002:a17:90a:12cc:b0:267:7021:4e3c with SMTP id b12-20020a17090a12cc00b0026770214e3cmr6084202pjg.8.1691293049589; Sat, 05 Aug 2023 20:37:29 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PULL 16/24] linux-user: Use MAP_FIXED_NOREPLACE for initial image mmap Date: Sat, 5 Aug 2023 20:37:07 -0700 Message-Id: <20230806033715.244648-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use this as extra protection for the guest mapping over any qemu host mappings. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/elfload.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 2aee2298ec..0c64aad8a5 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3146,8 +3146,11 @@ static void load_elf_image(const char *image_name, int image_fd, /* * Reserve address space for all of this. * - * In the case of ET_EXEC, we supply MAP_FIXED so that we get - * exactly the address range that is required. + * In the case of ET_EXEC, we supply MAP_FIXED_NOREPLACE so that we get + * exactly the address range that is required. Without reserved_va, + * the guest address space is not isolated. We have attempted to avoid + * conflict with the host program itself via probe_guest_base, but using + * MAP_FIXED_NOREPLACE instead of MAP_FIXED provides an extra check. * * Otherwise this is ET_DYN, and we are searching for a location * that can hold the memory space required. If the image is @@ -3159,7 +3162,7 @@ static void load_elf_image(const char *image_name, int image_fd, */ load_addr = target_mmap(loaddr, (size_t)hiaddr - loaddr + 1, PROT_NONE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | - (ehdr->e_type == ET_EXEC ? MAP_FIXED : 0), + (ehdr->e_type == ET_EXEC ? MAP_FIXED_NOREPLACE : 0), -1, 0); if (load_addr == -1) { goto exit_mmap; From patchwork Sun Aug 6 03:37:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710870 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826079rwb; Sat, 5 Aug 2023 20:38:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEImUXlFh8D0Onvds2xLTTnXKDDsDOATNKx/dFpfoEhBuhKQbsl4J5Zzpe3bslJ0Tn/qZx8 X-Received: by 2002:ac8:5bd0:0:b0:403:b382:613f with SMTP id b16-20020ac85bd0000000b00403b382613fmr6704028qtb.44.1691293128512; Sat, 05 Aug 2023 20:38:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293128; cv=none; d=google.com; s=arc-20160816; b=hEXM19PBjgN5wc/Bjr4mZ3iiL0ecDoIwIJ9CMpdv0FzYDhl/i0YnTvoYYescOOEsGd NsMCzD2Q43iozT1VuJPvr/Iq5pRMJtY7LWOicgC70ECFCoW7riTSU3O2rYVf7j3c9h1w 5dY3zMm2biPMGqagk83n6C2br3QUI9s69QKZbO5pATVI6zT2ZUwIyLNuQbscIrGGdHgg 4ZtwY5LXz7SHX1EvPunpxkC1/wnQz9sLlW1XEgMoc6U8LwwaFvdI+5XdJsgsu5drT3b+ ZEndMKHTFGesQSJzF+WbDSHg0j7Qf6FcXkFikSUguHzA/tFh8+frI+ft0I7J4+O9h5K2 GQFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gDTWs7pBzjEM4yDIiLCCxRn3NjvKLf/PjlJHIm+hkqo=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=NsW37xHVi4o78UKAeR8N66UUHWz4TygJJtdbe1sSKW/yhCe2udja14/7oodLU+96Rv IDqDGmb7DMsXcWBckw5tCYTl8YzAte9zIH7HhC0dV/p6c6jw57o06J6BZTjIo5u8rfwp RjTyN0VK1Y+/IUly2yVjByQ+YYDr/zCq57OA+FaBEjpdEOUP8uBXLcaHF2cpWextv6Wu cyea5ZzRQZ7oWAHukXB4FYdH1WUwTfrJVIKlRGE0d1K7WNkDD1GkPWn9foNRJmm5Ixcn GBXd68InZQFSVocHORMEwr0vLRmjKyemW1+B9ZhpeyCYeXSAOxxj+hRZkpUAzv9DZ73o JTIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=efVtzpR1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i18-20020ac85c12000000b0040fd1f4aa51si3358993qti.48.2023.08.05.20.38.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:38:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=efVtzpR1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUaF-0003iS-LB; Sat, 05 Aug 2023 23:37:35 -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 1qSUaD-0003gg-85 for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:33 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUaB-0007Zq-Ki for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:33 -0400 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-2680eee423aso1672764a91.2 for ; Sat, 05 Aug 2023 20:37:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293050; x=1691897850; 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=efVtzpR1l/tn9lMq2lyqAy5nYGl8zods7/8Z8/Z+GtAMM96FLCvR2qZ5gwmniUr8L0 IoA9WzzZkrVlqeDeLg36DU/86aI3/hatHyIX5fwydciy0ifkSqg8Y2ZfbqX0a4VzyD8R l4s2qvgrvAij9XwDjo5vT+yLARk0GI+FYRXknL5nW6bNCbi1LXGPKCGcCCKqu62XqtQk tcibedTwoejHta5tQvNrmFIUaRlQnJISrC9rF9UGDEEf08FQMx688mdlaVoQ+LEtRUdG cH5mI6k6QCEJZ7KK/LKnj6pDS1iCLMXpKmwqXbxnJRZyl6pssKLSHoXMdlmQT3apOO19 IS6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293050; x=1691897850; 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=Cxh8wE8t7X+H9gbtC1jbFgXJEhujHq4/WWDE2YiLRuCrvKU7872Bsg8ERX3CTrMzMD thZxLExm5Kp7mpvPKZGLN6MbuI9Bw7GqbBnkcU130vGQF+Ct+Q8GjU4ZWGdP+RPPo5X8 dTjL/GGPl/QtbRwE0aVDzj33Smyvgu4TcZD3pXgorKQavi4HzlWxCdg1Cb3yspD0bMPr oBtUTXvj207Bn6zTt0PAq+Ciu0Z6aFrDBvaxkOOmlEIhpghcMqO+Dwgpu+WwVpKkbHPo CbxNH3AHGgcfE+wfI/yCg9mX39tB6HYJRrZUrTvx1uIZsZG1EBPGezspWtXzVFRWLUx9 VEXw== X-Gm-Message-State: AOJu0Ywjx834d3nlxKedh63kOntjeF754HffCa4oE9UwiTOOrLRCo/mr ljR4Vpw0kvRsM3G5tbWt9UQjgSmLG/gy/pauEtQ= X-Received: by 2002:a17:90a:d30b:b0:268:553f:1938 with SMTP id p11-20020a17090ad30b00b00268553f1938mr4372119pju.4.1691293050478; Sat, 05 Aug 2023 20:37:30 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PULL 17/24] linux-user: Use elf_et_dyn_base for ET_DYN with interpreter Date: Sat, 5 Aug 2023 20:37:08 -0700 Message-Id: <20230806033715.244648-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Follow the lead of the linux kernel in fs/binfmt_elf.c, in which an ET_DYN executable which uses an interpreter (usually a PIE executable) is loaded away from where the interpreter itself will be loaded. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/elfload.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 0c64aad8a5..a3aa08a13e 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3106,6 +3106,8 @@ static void load_elf_image(const char *image_name, int image_fd, } } + load_addr = loaddr; + if (pinterp_name != NULL) { /* * This is the main executable. @@ -3135,11 +3137,32 @@ static void load_elf_image(const char *image_name, int image_fd, */ probe_guest_base(image_name, loaddr, hiaddr); } else { + abi_ulong align; + /* * The binary is dynamic, but we still need to * select guest_base. In this case we pass a size. */ probe_guest_base(image_name, 0, hiaddr - loaddr); + + /* + * Avoid collision with the loader by providing a different + * default load address. + */ + load_addr += elf_et_dyn_base; + + /* + * TODO: Better support for mmap alignment is desirable. + * Since we do not have complete control over the guest + * address space, we prefer the kernel to choose some address + * rather than force the use of LOAD_ADDR via MAP_FIXED. + * But without MAP_FIXED we cannot guarantee alignment, + * only suggest it. + */ + align = pow2ceil(info->alignment); + if (align) { + load_addr &= -align; + } } } @@ -3154,13 +3177,13 @@ static void load_elf_image(const char *image_name, int image_fd, * * Otherwise this is ET_DYN, and we are searching for a location * that can hold the memory space required. If the image is - * pre-linked, LOADDR will be non-zero, and the kernel should + * pre-linked, LOAD_ADDR will be non-zero, and the kernel should * honor that address if it happens to be free. * * In both cases, we will overwrite pages in this range with mappings * from the executable. */ - load_addr = target_mmap(loaddr, (size_t)hiaddr - loaddr + 1, PROT_NONE, + load_addr = target_mmap(load_addr, (size_t)hiaddr - loaddr + 1, PROT_NONE, MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | (ehdr->e_type == ET_EXEC ? MAP_FIXED_NOREPLACE : 0), -1, 0); From patchwork Sun Aug 6 03:37:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710883 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp827015rwb; Sat, 5 Aug 2023 20:42:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkogZlIQyWh99B4MxxdJCBO9Xcr3mib+gCh52KRjWDrIvaQCjXB4fK1cMYpKlRcg//sWZF X-Received: by 2002:a05:620a:424b:b0:76c:bdbd:c51d with SMTP id w11-20020a05620a424b00b0076cbdbdc51dmr6801662qko.66.1691293342559; Sat, 05 Aug 2023 20:42:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293342; cv=none; d=google.com; s=arc-20160816; b=PxrlajbfWkmhOFPc3H8Dtrdn5W9ttC4EV5y6DqIBDCKB/hZby9+nhbDCde0FqeqnBs bvdOffyOT1+Im57cy2NkOBHKL2qzKMQipS1PI4P15SmLbZKIp9AKR+hf9n3GP967liQS xVhVSO3JzUQuqcZFBxvfc1pCSRU/6DhfKH13CXOEs8CwPHFA165NtBjgHtTCXOlir2MK pts1u+xIbTIR1Bo2FO/x2wWnadfsraQoE5T6a4qe7nFvzQd4YNhII1yBYTK/fAQtpK+s bs49X9NiN94koe1h0YZBzCZQ0hinUd4/HsN1JsbAfphWkH2gL9uNUaHXrDzyJOZfo0Tg iBSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LEtd4K5hRnVc6hrl39zIoY3R0ensohNvKsrzBxsSkfw=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=qPkAwZsTMzQX5XPdQRWmJc4eWZBRQ6WT+yMMM8eYGqaGf/6oKWzTI9dg5ef8Yrak7i cQi/z1nqMeIUtg6U1/gFqnQLgGe6bOxheRiITs5Z1L/Dr1K7DWOAUpzI4SpGTpRcI+Gc xnUQCTuUeiEbuyN+inAqEN00P3MivAmGeroP40eGjt4AIfoyUPym6XtghauOUkbCEGQy GJvsx2KHfgkwQKxkuNGcXHQJNR96qxMNeMwkpTm24pz30KrzaUTzK6JIyhrSBkcLxFBj Q5NND8+0c79yuwkdv/XVzN+Bn76JRSCcx1cCpd6nqdtIn6dwqKkjjEyIWMu2pYu7behq /TyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cHS0OJKY; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 14-20020a05620a040e00b0076cbc52a165si3065210qkp.722.2023.08.05.20.42.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:42:22 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cHS0OJKY; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUaG-0003j4-8t; Sat, 05 Aug 2023 23:37:36 -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 1qSUaE-0003hZ-5z for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:34 -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 1qSUaC-0007a4-FF for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:33 -0400 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-26837895fc8so1833515a91.0 for ; Sat, 05 Aug 2023 20:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293051; x=1691897851; 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=cHS0OJKYCyquIm7FeeoY6cLA26O5uN0gbQ5qPoRGidvPqJtadAUMq9SKTQgoDFv9sT 6J3XpXcWvwvyaJzoVgYRTtd5OqffL6QgpoBZ6M/ykbC/Aei0TL/FS5r5JaBgD5brwHYp PxOfWXkBAWYZ136cgA1/6Fz0Dv1lUerYzMNvUlfd9UpI3+ryunosANHL9aTppVyuGZE8 hHnRHP96+7ADXcy0FVFIYkDKdG2MCjEIJuBPb/GTzT7EKN1RZjp4ha0yUHLJF0OSgPIH GHUqW7LOtMOEb46l0Ib1I0otLeBDSq/r40brQS9Cn+wPEVK4ykOEeGS8EhcfdQl5hqOm 4cAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293051; x=1691897851; 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=Jw1VzOne/iOopLLuS3nxjFaV7diuAa95DoIZi60dg589oXKXRXNueasXdgrKKtdmUQ 6pyJfN0pasRaHGDxcSvfM3KK81kBVnABc+uaVzC7rRhE8plxve0CFCPI/Dt9Q1MJ1q8T hPK2Ope540uzbPZCsrb+PiKrSRYDrelUcdPKDEJJQIPrTXGNz7spa5XnmXH+TKF47ZVC lVzI9FHiYCIy+rFKNdQem4yJXX+BOLteY0YaPihNtqnuauKieZjy0B6CLC8S18V6HNxS ttfmDH7RQY4JZPJlU7ZLU0xH4/VSqm5IRULqbmXDCi9Nd0VhG9ueeSUxBl7WijcW2jhL 6WMQ== X-Gm-Message-State: AOJu0Yw2HvLhJi+F514FBqT7ab2PnpPj5mFmFP9k+WaoAxFEauknz7zw FgUnpJmyld88GEm0aAoE+Dwa3i77bEUKkRw94Pc= X-Received: by 2002:a17:90a:4587:b0:269:155a:c936 with SMTP id v7-20020a17090a458700b00269155ac936mr4496416pjg.28.1691293051161; Sat, 05 Aug 2023 20:37:31 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PULL 18/24] linux-user: Adjust initial brk when interpreter is close to executable Date: Sat, 5 Aug 2023 20:37:09 -0700 Message-Id: <20230806033715.244648-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Helge Deller While we attempt to load a ET_DYN executable far away from TASK_UNMAPPED_BASE, we are not completely in control of the address space layout. If the interpreter lands close to the executable, leaving insufficient heap space, move brk. Tested-by: Helge Deller Signed-off-by: Helge Deller [rth: Re-order after ELF_ET_DYN_BASE patch so that we do not "temporarily break" tsan, and also to minimize the changes required. Remove image_info.reserve_brk as unused.] Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/qemu.h | 1 - linux-user/elfload.c | 51 +++++++++++++------------------------------- 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 802794db63..4b0c9da0dc 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -31,7 +31,6 @@ struct image_info { abi_ulong end_data; abi_ulong start_brk; abi_ulong brk; - abi_ulong reserve_brk; abi_ulong start_mmap; abi_ulong start_stack; abi_ulong stack_limit; diff --git a/linux-user/elfload.c b/linux-user/elfload.c index a3aa08a13e..fa0c9ace8e 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3109,27 +3109,6 @@ static void load_elf_image(const char *image_name, int image_fd, load_addr = loaddr; if (pinterp_name != NULL) { - /* - * This is the main executable. - * - * Reserve extra space for brk. - * We hold on to this space while placing the interpreter - * and the stack, lest they be placed immediately after - * the data segment and block allocation from the brk. - * - * 16MB is chosen as "large enough" without being so large as - * to allow the result to not fit with a 32-bit guest on a - * 32-bit host. However some 64 bit guests (e.g. s390x) - * attempt to place their heap further ahead and currently - * nothing stops them smashing into QEMUs address space. - */ -#if TARGET_LONG_BITS == 64 - info->reserve_brk = 32 * MiB; -#else - info->reserve_brk = 16 * MiB; -#endif - hiaddr += info->reserve_brk; - if (ehdr->e_type == ET_EXEC) { /* * Make sure that the low address does not conflict with @@ -3220,7 +3199,8 @@ static void load_elf_image(const char *image_name, int image_fd, info->end_code = 0; info->start_data = -1; info->end_data = 0; - info->brk = 0; + /* Usual start for brk is after all sections of the main executable. */ + info->brk = TARGET_PAGE_ALIGN(hiaddr); info->elf_flags = ehdr->e_flags; prot_exec = PROT_EXEC; @@ -3314,9 +3294,6 @@ static void load_elf_image(const char *image_name, int image_fd, info->end_data = vaddr_ef; } } - if (vaddr_em > info->brk) { - info->brk = vaddr_em; - } #ifdef TARGET_MIPS } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { Mips_elf_abiflags_v0 abiflags; @@ -3645,6 +3622,19 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) if (elf_interpreter) { load_elf_interp(elf_interpreter, &interp_info, bprm->buf); + /* + * While unusual because of ELF_ET_DYN_BASE, if we are unlucky + * with the mappings the interpreter can be loaded above but + * near the main executable, which can leave very little room + * for the heap. + * If the current brk has less than 16MB, use the end of the + * interpreter. + */ + if (interp_info.brk > info->brk && + interp_info.load_bias - info->brk < 16 * MiB) { + info->brk = interp_info.brk; + } + /* If the program interpreter is one of these two, then assume an iBCS2 image. Otherwise assume a native linux image. */ @@ -3698,17 +3688,6 @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) bprm->core_dump = &elf_core_dump; #endif - /* - * If we reserved extra space for brk, release it now. - * The implementation of do_brk in syscalls.c expects to be able - * to mmap pages in this space. - */ - if (info->reserve_brk) { - abi_ulong start_brk = TARGET_PAGE_ALIGN(info->brk); - abi_ulong end_brk = TARGET_PAGE_ALIGN(info->brk + info->reserve_brk); - target_munmap(start_brk, end_brk - start_brk); - } - return 0; } From patchwork Sun Aug 6 03:37:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710877 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826278rwb; Sat, 5 Aug 2023 20:39:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGXXmUR+8Xo1Dm6ATHYCadOt5PFzb2WoplbMuIc26qf+4cG/7WmEP51m4TN0nhmfz7DvWyH X-Received: by 2002:a05:622a:181d:b0:405:56bb:343b with SMTP id t29-20020a05622a181d00b0040556bb343bmr7624824qtc.41.1691293181336; Sat, 05 Aug 2023 20:39:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293181; cv=none; d=google.com; s=arc-20160816; b=swAcU35J0FVzFai8J6hw8ZLoX+a5KrNkEgtv+sO/pEFKCGHrxWo3Mq3VGNj5JzeYte qtNEadUOQkrKpHxBnjlVTO8/Nk5G57hIY1E5NpJ9pxpGCsHrRSwvYKmqSJ1r4ISu8nSz rlatOhE3nIIUAIHbjj65fo3GGoY52jV+1vqmP6Kjmvya3zmxncwaQM70wfDixBy23S32 eQB6v2CbxCxFKoQK6nSnYDdMiXYOfpNwX4x9w5zVEpJ5QbuT3yF5lV2XFLCGlP4kGPOi Cs427rQuvrPdp1IuGdF6xC/7iQsv50Kii7E88zZltuylUDHxPFkfF9xXqvxdFfKlAPfp fn5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4+a1ntD1nPZIq5/3BuYdNWBqjL6H8GnZs4Nnik5eIQQ=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=y1ODa/3mUVvOdIps3UeUqbfU3aS4ncUs5u83W7PriCyVoG2y0o5DfE34RCf8LqClQB KbMgjyjJ3rlycS1uMYA6jHBTlDFALgcimaToMr3/ZTEzdwZxvmp7m3vNHUIpcXx9uSbh bgQIHSr8wErJpL5aJgVUBEHHYWClXP+I/HJ3eFqlLKBjvyGU8ewh/Y48iOyA7Jj6wiaF x0jJ1q5kVkVuDJ2IjxtB12KpNzFtVMd3H8P0fwd6p0oFqy6yYYDMCOYefcPVHso4DEFd ZPsUDyyqTXK8Q9+T9tj6eRYlS7GLUN3F0MHmlE24UEpGC/WwiUrwHgoA4HBLhv96pICF dMLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VtfJ3gn6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id l8-20020a05622a174800b0040da281e4d8si3397033qtk.517.2023.08.05.20.39.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:39:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VtfJ3gn6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUaG-0003j5-Er; Sat, 05 Aug 2023 23:37:36 -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 1qSUaE-0003hu-SH for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:34 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUaD-0007aR-Aj for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:34 -0400 Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-517ab9a4a13so2445778a12.1 for ; Sat, 05 Aug 2023 20:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293052; x=1691897852; 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=VtfJ3gn6ABglBbG23wqawv3eaDnP34LqhXTaK431QvWp4niDYCuo/Ee8fQSRhChIUy p8+PhimpmvkbpQOUsvGCbDOAR+yMpEOShzJArBm5THNoto1AKpKOkGDpse187DfTZ7e4 epSI1plzAFXXp1TIDAPUvCjK84hDD8Zd0Jh9gx7tRH9vzY23SeM2DdJ3Dybiwmb/YhHW aBvR+FSOXtGxg9h5JkjxnVoa//PhYClcZsTm2Hh632OsObwwoYRv3AnwKXYFmc0u9ArT hA7rkhAS0eZZU/F460t9oCSmJ/xaZ49fyk2v6jSse/ko1kRYJeV51lpmq7PVP0jPq/Vo A/Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293052; x=1691897852; 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=Jqh/VNsMq8HmVHlkvGOD2CgYdMjy6pEKFSDkVNi6Ab4fG2aw6UKGAgQdYVFwFJrgOc 87BnCVL9/sf5TKRziGXs1Ck2mh1oGVxBlX61CMxISAvv763iRNlEx0pxdp928gLVq/oO pdOOUMO1Lo/14t6+MUhJ6v1mk4w0sXTb4JlEa9xYKHBSTJhJS3T6Bo7juBTJKOp8Efn1 hY0MEtNNcYnlKB4XqASo6U689di/y6XumWkTm+CGhF8fsIS9NCL6toMZBVQQjjPet48l J/RQ5Isaz/LxmqCsowLgHxSxnq20JyOpE0Sm9PNaXWhprfFqjhx0ImXJ7exTb9ri5+9T ZEfw== X-Gm-Message-State: AOJu0YzE9M/W4M7pRhiyM8NL0aVHS9Pxc9fukohxRXRSRhFra50GJ8cm 92nV2PjL7QCrQKAT/SiiQkP0IwuKcGCuBGzCKM4= X-Received: by 2002:a17:90a:8043:b0:269:46d7:f1db with SMTP id e3-20020a17090a804300b0026946d7f1dbmr1912631pjw.32.1691293052017; Sat, 05 Aug 2023 20:37:32 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PULL 19/24] linux-user: Properly set image_info.brk in flatload Date: Sat, 5 Aug 2023 20:37:10 -0700 Message-Id: <20230806033715.244648-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x534.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org The heap starts at "brk" not "start_brk". With this fixed, image_info.start_brk is unused and may be removed. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/qemu.h | 1 - linux-user/flatload.c | 2 +- linux-user/main.c | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 4b0c9da0dc..4f8b55e2fb 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -29,7 +29,6 @@ struct image_info { abi_ulong end_code; abi_ulong start_data; abi_ulong end_data; - abi_ulong start_brk; abi_ulong brk; abi_ulong start_mmap; abi_ulong start_stack; diff --git a/linux-user/flatload.c b/linux-user/flatload.c index 5efec2630e..8f5e9f489b 100644 --- a/linux-user/flatload.c +++ b/linux-user/flatload.c @@ -811,7 +811,7 @@ int load_flt_binary(struct linux_binprm *bprm, struct image_info *info) info->end_code = libinfo[0].start_code + libinfo[0].text_len; info->start_data = libinfo[0].start_data; info->end_data = libinfo[0].end_data; - info->start_brk = libinfo[0].start_brk; + info->brk = libinfo[0].start_brk; info->start_stack = sp; info->stack_limit = libinfo[0].start_brk; info->entry = start_addr; diff --git a/linux-user/main.c b/linux-user/main.c index cb5e80612b..96be354897 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -963,8 +963,6 @@ int main(int argc, char **argv, char **envp) fprintf(f, "page layout changed following binary load\n"); page_dump(f); - fprintf(f, "start_brk 0x" TARGET_ABI_FMT_lx "\n", - info->start_brk); fprintf(f, "end_code 0x" TARGET_ABI_FMT_lx "\n", info->end_code); fprintf(f, "start_code 0x" TARGET_ABI_FMT_lx "\n", From patchwork Sun Aug 6 03:37:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710882 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826771rwb; Sat, 5 Aug 2023 20:41:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH7lMV5p2xGOSJ4g9YAZOhnc2H3lBL3LD3ifYm2+Ip075QtFIN62PHLyt+LrqWls5jz5pdN X-Received: by 2002:a05:620a:440a:b0:767:8546:b374 with SMTP id v10-20020a05620a440a00b007678546b374mr4976587qkp.14.1691293294813; Sat, 05 Aug 2023 20:41:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293294; cv=none; d=google.com; s=arc-20160816; b=qXx6oVVP2pml3cjXTseBWZR51ZJSBU0Vvhf6a0jCDfZ9gpgKfjK3DrRra27WWp+2yz 07PnkY6A6soW/KiG/Hs8U9l3cHienL/Gyt72fhIiacwUJhnIem0Pu+Y7aLneZIMYK/m1 kynzCCOEJX4TgTJSit1OI6WdpQTkA1WLpm1b59Bk1AwyYpO7ZDWhS6xPtR0N+07Hyxpj 9SDoPMbFLo30qh4kKeT/Sd5NLbVw6g6f0pEcw0/BvgjfHrOE/DT4X3ifazc54UoEbxur DLKYhySCdInKTHVea8b9lH1Wwd05NwKh04EIDBsvviYSXrxsXnXUkMs0RIMarSSQtZRl XaUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0VLnmjiDjAi6Gl+LJx+pmU5KrGv5xMTSD4fN49XrjM0=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=L0FuWfQG4qbr7bPRpj45gI6MJQTGKeSWV4htPzROp9tveX6zFq0v0hRs80noa7Swpo HOmEnPQy8MofCjK99R3AirhYGYKSujaX6rQBvLezlRsgZgMpA7PUe0XXBRmkDbY2g6Yf piJmwg3zGGGq6VzresUVTb7QvYJ5vZcFxFSDD93+bwiWAhMqmo5DvaHnYwzfMcTdcRUp Yz/Db0EdTEORxa7SS/dF6FeZy0vSIG7h1Sd43/zACFmcpGCM47KKer7oh50lHgAYpBZW Z0IJbA9XCPENHNRN9ll9IaOpbugygAgpW7c0byNpgQbLYsqNRtsZNyW84C8TLJ5bGH3B QMXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k86kupew; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m23-20020a05620a215700b0076cc4d494c2si3086281qkm.88.2023.08.05.20.41.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:41:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k86kupew; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUaH-0003jU-53; Sat, 05 Aug 2023 23:37:37 -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 1qSUaF-0003ih-OY for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:35 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUaE-0007af-5t for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:35 -0400 Received: by mail-pg1-x533.google.com with SMTP id 41be03b00d2f7-564af1b3a9fso1651820a12.1 for ; Sat, 05 Aug 2023 20:37:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293053; x=1691897853; 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=k86kupewmSW1Nd86OOjC3/oRzVdxXYuhjhYYhIkfjZdxm2OK0pIciX5x/6LFy5F/Cx eBzoQpzclceV7WYJjWje3diFdSqc7ZXxcAUrBR+gf78QqXJl5JxdDju+FjcwywVLqnER FPlU3KsZElM/WFzMX5rutTI35K3oJFrYo7MnLrOpGOgqJ00mCoto8MRqcFnhhGX1431X Amv0lxJ4+3oaBkzvXqwbCWby2fUNkLTUp2HW1KLdL2ORpdVTMqCTKBsMDz4x0g2gptT2 zGPmCRrH+RdgpJlfCI5rtjDo2lhWzDyN1m/MvyM8Q2ogeXY/hVHazrzmM9ZpW7CAWQ6G y2bQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293053; x=1691897853; 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=Oq1CGL3NtTUtmuqj09mtacG+WZH4Gf2gavSeoQgPa/vk99IsfW+6MUAe49ckGWx5tk vZ4/kNd0esBe3A1MrlaCBn72hf2YrqCUwx1I2RSDnTFtNZeNOvdiPtv9zuDD5/J7WkeB MakNGCxmenHfxMI/drrKakHv7lSwt88tr/xYeeC4jclc7wQvRtEzXGF8pVhOGmYQv3xi XjalJf1Q276UqFw7OJLR2BdaQELjDNnO9QR91jCBXaMxBXacsJn8z930UlBvyZsikXaR jUYC6AEkx4Q6aAqaaZwxCV9R0WYb5QW9cuRtVVyya8nNUKEkgNfSJJEhmfxgrIl5n5s3 PgJA== X-Gm-Message-State: AOJu0Yw4Bc1XEcBY50d51rHe5FMaYktqGOHgi/if7mmzvuN+qYnKSuLr fZVZZsDG9E7MgSeIGSYqDS8BeoMUfrlPyuN2wYw= X-Received: by 2002:a17:90a:fad:b0:263:161c:9e9c with SMTP id 42-20020a17090a0fad00b00263161c9e9cmr4614220pjz.12.1691293052938; Sat, 05 Aug 2023 20:37:32 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PULL 20/24] linux-user: Do not adjust image mapping for host page size Date: Sat, 5 Aug 2023 20:37:11 -0700 Message-Id: <20230806033715.244648-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x533.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Remove TARGET_ELF_EXEC_PAGESIZE, and 3 other TARGET_ELF_PAGE* macros based off of that. Rely on target_mmap to handle guest vs host page size mismatch. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/elfload.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index fa0c9ace8e..e853a4ab33 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1959,15 +1959,6 @@ struct exec #define ZMAGIC 0413 #define QMAGIC 0314 -/* Necessary parameters */ -#define TARGET_ELF_EXEC_PAGESIZE \ - (((eppnt->p_align & ~qemu_host_page_mask) != 0) ? \ - TARGET_PAGE_SIZE : MAX(qemu_host_page_size, TARGET_PAGE_SIZE)) -#define TARGET_ELF_PAGELENGTH(_v) ROUND_UP((_v), TARGET_ELF_EXEC_PAGESIZE) -#define TARGET_ELF_PAGESTART(_v) ((_v) & \ - ~(abi_ulong)(TARGET_ELF_EXEC_PAGESIZE-1)) -#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE-1)) - #define DLINFO_ITEMS 16 static inline void memcpy_fromfs(void * to, const void * from, unsigned long n) @@ -3240,8 +3231,8 @@ static void load_elf_image(const char *image_name, int image_fd, } vaddr = load_bias + eppnt->p_vaddr; - vaddr_po = TARGET_ELF_PAGEOFFSET(vaddr); - vaddr_ps = TARGET_ELF_PAGESTART(vaddr); + vaddr_po = vaddr & ~TARGET_PAGE_MASK; + vaddr_ps = vaddr & TARGET_PAGE_MASK; vaddr_ef = vaddr + eppnt->p_filesz; vaddr_em = vaddr + eppnt->p_memsz; @@ -3251,7 +3242,7 @@ static void load_elf_image(const char *image_name, int image_fd, * but no backing file segment. */ if (eppnt->p_filesz != 0) { - vaddr_len = TARGET_ELF_PAGELENGTH(eppnt->p_filesz + vaddr_po); + vaddr_len = eppnt->p_filesz + vaddr_po; error = target_mmap(vaddr_ps, vaddr_len, elf_prot, MAP_PRIVATE | MAP_FIXED, image_fd, eppnt->p_offset - vaddr_po); @@ -3267,7 +3258,7 @@ static void load_elf_image(const char *image_name, int image_fd, zero_bss(vaddr_ef, vaddr_em, elf_prot); } } else if (eppnt->p_memsz != 0) { - vaddr_len = TARGET_ELF_PAGELENGTH(eppnt->p_memsz + vaddr_po); + vaddr_len = eppnt->p_memsz + vaddr_po; error = target_mmap(vaddr_ps, vaddr_len, elf_prot, MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0); From patchwork Sun Aug 6 03:37:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710881 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826514rwb; Sat, 5 Aug 2023 20:40:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGw2081YTY1YjBtQxpHE7b27y1b5ajRj1Gat8V4LM8heLugZfKN8O7TCXHgVKEjmarGHyNB X-Received: by 2002:ac8:5702:0:b0:403:fb43:bcb0 with SMTP id 2-20020ac85702000000b00403fb43bcb0mr7218038qtw.46.1691293232811; Sat, 05 Aug 2023 20:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293232; cv=none; d=google.com; s=arc-20160816; b=mPe4ihBnY2CaVQtfE08d0gb33OCxsvjnMdr+HgTPYA/DpKjcbNZjvYakTqDSEe2a6m pwfZNjRInsZ6J+CmZggacv26umnOXerM9eqp7dsHYFcNIdJCErP0JDe+GL0JhnPUztX1 3Scfef+A+Hp1iBO6GxUpuaAdODSCyLSgjoI/T6ex27sV686MDbPiKghJizOAo7nAlfYl uiZDfLkRGYGT4vCoDdaOh155/gg4adr7rPS6JLQl0PKeqNH3uBfxBkyvacxxRKr49zDY TXGzj0n+N1tbVv7g42X+lj+BhEFi9XRrow3Nr3nZponHLxhJeFZA/ORvnTSAi/wvAFNP EqVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DQhgJn+xuWrfht0tZgQrit41wBeRtDQVHgOUdbJWgEM=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=Yujg3V7xJEHPzV6u/xblO5HGt3PxnHg8rSzm7XHfvFxsboqr3B+bIqMMlZ6lXwo9/g lqS/by8e6sv+X4hoDaOTgwNfBAZP0SZ57C4dgeifUVUVJZUC5AkR1LDNTkURjQ7/68u5 eclZoL8TUBl14JfNze3Jgn2LZpeTAnV4M9A4dMrS9hfecsKv0kqORRRnA5hS8/YpVgZ5 Vyqe6S14/H0rXH1CCEIsTDt7nZeOHDneMMKMxrpZ1mq1UNwdjoTmg9jQdikVIPDRqtgL B1vbz4JFTTrrGiVM1UclVZEsw7qOGFFkwoBtjMBcTHYFzTpBAazDWLxnjfD4dKnDifTF n5sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hacv99Wm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o15-20020ac87c4f000000b0040fc209cc9bsi3337122qtv.1.2023.08.05.20.40.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:40:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Hacv99Wm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUaH-0003jc-M5; Sat, 05 Aug 2023 23:37:37 -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 1qSUaG-0003j8-LU for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:36 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUaF-0007ay-3Q for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:36 -0400 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-2685bcd046eso1672424a91.3 for ; Sat, 05 Aug 2023 20:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293054; x=1691897854; 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=Hacv99WmJ9BnWfmFp/KhMmwj27f+9kUpj9WVeOdQwkjTRsabZU+Z8OKIraTjTaCJt4 oERBS4vAQxs/RzbtQiG5IsNLPvSEkWzdtDkX1sHwSTFAXRmtKRZNjVi6HZufhiva7OCq sfSd827Gt9D+lY5ZwCnDaIRJSMPbqLt5WCQGOlcr4v8hA1gZ16Z5k9iDbU0LDNDSiw29 EzZ/MuekqQr1Z/kJaMjeuzTSrKstVkuzSqRWG8qR+2Wq/fG6VJnIN/j8S5UpBawWje0m 9o7X/q1mmccpACQc4l/cf30RnxM6F3JFZnBhz9qwFhvbUXVuCVP9i/pbKUfwaycAdVv6 0JYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293054; x=1691897854; 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=CL92eM0R6lmEE1m+Tt3OMRH0zviwnvB0LchPUODD/pd2uHWPWd4tN9PflIQfGb3vuy 7ey9NC5LIZimwukM7CG6UO8bh49NPtUy8HXVo6uUHLRLSxsU336SKN1xaE8kkxkjly7P HMtygs1PD5c097+/6ebyeog9jzLJT8q1BmE2csPJ5Je88OMl4DmvbDFzl7RIYAXc62as QvDfVgD5W6vtsnDZa3Qb9qQmBscBMDI1mDoxbJ1Jfu2zThhGGDgpuHgaKnLGtyQ5jOF4 TjtqtdRwUuSz2EVG1FJd62Q4MjO9DSlii9eGNsGAikrUIRWTNq9G1HGZEKrs7Rgzz/P6 tgIQ== X-Gm-Message-State: AOJu0YxUbP7QQ2kw/JfVrstC/i01vNaND/aYijzKeKXIff9WlG6Y4jDM Pwj8tsLi21gKAAwlVFm9rqfOasalUBXyXFnEoVk= X-Received: by 2002:a17:90b:ed4:b0:262:df91:cdce with SMTP id gz20-20020a17090b0ed400b00262df91cdcemr4447858pjb.23.1691293053748; Sat, 05 Aug 2023 20:37:33 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PULL 21/24] linux-user: Do not adjust zero_bss for host page size Date: Sat, 5 Aug 2023 20:37:12 -0700 Message-Id: <20230806033715.244648-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Rely on target_mmap to handle guest vs host page size mismatch. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/elfload.c | 54 +++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index e853a4ab33..66ab617bd1 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -2212,44 +2212,36 @@ static abi_ulong setup_arg_pages(struct linux_binprm *bprm, /* Map and zero the bss. We need to explicitly zero any fractional pages after the data section (i.e. bss). */ -static void zero_bss(abi_ulong elf_bss, abi_ulong last_bss, int prot) +static void zero_bss(abi_ulong start_bss, abi_ulong end_bss, int prot) { - uintptr_t host_start, host_map_start, host_end; + abi_ulong align_bss; - last_bss = TARGET_PAGE_ALIGN(last_bss); + align_bss = TARGET_PAGE_ALIGN(start_bss); + end_bss = TARGET_PAGE_ALIGN(end_bss); - /* ??? There is confusion between qemu_real_host_page_size and - qemu_host_page_size here and elsewhere in target_mmap, which - may lead to the end of the data section mapping from the file - not being mapped. At least there was an explicit test and - comment for that here, suggesting that "the file size must - be known". The comment probably pre-dates the introduction - of the fstat system call in target_mmap which does in fact - find out the size. What isn't clear is if the workaround - here is still actually needed. For now, continue with it, - but merge it with the "normal" mmap that would allocate the bss. */ + if (start_bss < align_bss) { + int flags = page_get_flags(start_bss); - host_start = (uintptr_t) g2h_untagged(elf_bss); - host_end = (uintptr_t) g2h_untagged(last_bss); - host_map_start = REAL_HOST_PAGE_ALIGN(host_start); - - if (host_map_start < host_end) { - void *p = mmap((void *)host_map_start, host_end - host_map_start, - prot, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (p == MAP_FAILED) { - perror("cannot mmap brk"); - exit(-1); + if (!(flags & PAGE_VALID)) { + /* Map the start of the bss. */ + align_bss -= TARGET_PAGE_SIZE; + } else if (flags & PAGE_WRITE) { + /* The page is already mapped writable. */ + memset(g2h_untagged(start_bss), 0, align_bss - start_bss); + } else { + /* Read-only zeros? */ + g_assert_not_reached(); } } - /* Ensure that the bss page(s) are valid */ - if ((page_get_flags(last_bss-1) & prot) != prot) { - page_set_flags(elf_bss & TARGET_PAGE_MASK, last_bss - 1, - prot | PAGE_VALID); - } - - if (host_start < host_map_start) { - memset((void *)host_start, 0, host_map_start - host_start); + if (align_bss < end_bss) { + abi_long err = target_mmap(align_bss, end_bss - align_bss, prot, + MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, + -1, 0); + if (err == -1) { + perror("cannot mmap brk"); + exit(-1); + } } } From patchwork Sun Aug 6 03:37:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710871 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp826080rwb; Sat, 5 Aug 2023 20:38:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHo5qQEAyxDUjIPI+bVME+sNXTzJUzhEmiZyzxm7OqMwIF0FHgXSdURW+u8Xps38Xw15Dvg X-Received: by 2002:a0c:e950:0:b0:63d:42a1:4898 with SMTP id n16-20020a0ce950000000b0063d42a14898mr5548695qvo.50.1691293128873; Sat, 05 Aug 2023 20:38:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293128; cv=none; d=google.com; s=arc-20160816; b=KrCqxZfVzotxlfGffEkmUgPCVrxHxvLU4dH48H8+FVIWVWu70M2Mj2KTgdJIeQQtm2 8MZDvxS+Lf/VudPir/85T4xI/uJp9sOK3HsLuvPIrmYiT9+j0vZCaGCwo0P/H6yirPh7 Qon5246ItqzMM/j+b3SOfsHjLoA950cDbV7LQXxWF+ZT2p5AIrLAefDLca8j+06Wvg0H 5fdkrjAo7L919G5xo8vMopJM2bU453XGuZyU3rsBO+aTUe0dYx4zhtI5Bzd4Uq1kUbf7 gtHK1snPm1DqjIXfEemsZ8YaPQGBi3NBpDMejjfPT/7nAyyIWa8rX11iDh91zRPtit7I Ktfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BwFHtt7Rthrgzaq+94z3/B+V/hUuIkoTCUpTmlGBJ3w=; fh=e1NRMjxVMtV0F5wYJj2s+gr60lsrqkDmE/ulJ4pjdtQ=; b=s4d2QH+2Zyjk1wMAURcVfFP8FY9vVBN/yymXDRB3rsYtd6VaQvyxjrEPFU6Dlk0rCh aXOFrg+xsJL7gRO/l7GanDajWjuKLeVi4bJBVIPS3uuftthubEk904yKsWN9ASzIueJg xJa6YvH6XDXdbY/0T+Rq0mn5xBQNDje0PhFsP/QM0ZqisVKUNhVxkLIk10u11nFbBaPF hINjeVWdg9gVMWRfrSPco9ii6hlKQ0ZNvApqeTy+2ifFHjYUhcuO4tdHWEdFPi2qQEKZ Aw8emgCcucME/8C1p8NBP8GfDr2tBboQaSQ2Lk1YEbgzcGCRLegiyoRB9w3SZuKnQT13 lyVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="b+Oj/fWO"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id a27-20020a0ca99b000000b0063cfb677e5csi3368834qvb.374.2023.08.05.20.38.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:38:48 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="b+Oj/fWO"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUaJ-0003kX-91; Sat, 05 Aug 2023 23:37:39 -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 1qSUaH-0003jV-Bq for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:37 -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 1qSUaF-0007bH-QC for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:37 -0400 Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-26929bf95b6so889962a91.3 for ; Sat, 05 Aug 2023 20:37:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293054; x=1691897854; 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=b+Oj/fWOmU6XclRjmkD9QCPkfx6YoxidC4pen8HXCKgUDA3wBm7jGrl/l3PEmTHOxR VPm6stK1NMkT90cjPSzrR4CaxTHQYT6CCgYImtjDoLTdCQ+W0YcOFysVOXwZRP4ajrOt qNDvIYSLchcHOfxJ7BD7LOxAD8XzuzJuVjKH+dYUXFoZMI7k4Rh3GQJo6mdCZMXuFowF 7eXoike4cHo9rL2mRqCaSyb6SNgJPuxq2XC44VvDPvit+2THJK4rwUhiq+NaPVjmmJ2D lRekUIlJgujn3fQsNJ8aaMWzbxN6SbDtQEe15ZuCKc+4UA5usnIoFmy3ftrLrFl7HBMX hEag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293054; x=1691897854; 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=LVyK4s04gTPa95via1Uzql+Ivj81ai3OTVeMYk407yTci9N6fIQoDsYI+JjTRnzw0E SKsFkyCnjAAZ13wkN+o3BMgcooD+NFt+Iv0vriCjrhYNkjIDM81DGb5sHfuHFKhSMxJT FBqY2saThnU4RSwDGkvp/AoCVFTc5UMQikdUAnz5iP1CBdYcQdbEjDpo6zi9pHTDJfhd lmhOzt40uEcaVK7eCNbrAcTFsCTEy0OuZjqRcfT4fDoQRAZCk+4Mp3P9GyftUo2oT+GO MHk7rWFvPolCJiPyRBj2fxX7nf3OFG/5U31oRQ9sukuL/DD/YxdRVZzp29hPDAj8Akda WpXQ== X-Gm-Message-State: AOJu0YwXshqlc8m01LvF6dGXjbUpZITr3UVIOeJ3Zs9kaQrCtvdzV41N /QLLwL0Eg/GO+k3UMcr6Yb6JdjXpKN/LoD+gFDw= X-Received: by 2002:a17:90a:3d0a:b0:263:129e:80ac with SMTP id h10-20020a17090a3d0a00b00263129e80acmr4602846pjc.38.1691293054615; Sat, 05 Aug 2023 20:37:34 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Helge Deller , Akihiko Odaki Subject: [PULL 22/24] linux-user: Use zero_bss for PT_LOAD with no file contents too Date: Sat, 5 Aug 2023 20:37:13 -0700 Message-Id: <20230806033715.244648-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org If p_filesz == 0, then vaddr_ef == vaddr. We can reuse the code in zero_bss rather than incompletely duplicating it in load_elf_image. Tested-by: Helge Deller Reviewed-by: Helge Deller Reviewed-by: Akihiko Odaki Signed-off-by: Richard Henderson --- linux-user/elfload.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 66ab617bd1..51591a1d94 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -3209,7 +3209,7 @@ static void load_elf_image(const char *image_name, int image_fd, for (i = 0; i < ehdr->e_phnum; i++) { struct elf_phdr *eppnt = phdr + i; if (eppnt->p_type == PT_LOAD) { - abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em, vaddr_len; + abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em; int elf_prot = 0; if (eppnt->p_flags & PF_R) { @@ -3234,30 +3234,17 @@ static void load_elf_image(const char *image_name, int image_fd, * but no backing file segment. */ if (eppnt->p_filesz != 0) { - vaddr_len = eppnt->p_filesz + vaddr_po; - error = target_mmap(vaddr_ps, vaddr_len, elf_prot, - MAP_PRIVATE | MAP_FIXED, + error = target_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po, + elf_prot, MAP_PRIVATE | MAP_FIXED, image_fd, eppnt->p_offset - vaddr_po); - if (error == -1) { goto exit_mmap; } + } - /* - * If the load segment requests extra zeros (e.g. bss), map it. - */ - if (eppnt->p_filesz < eppnt->p_memsz) { - zero_bss(vaddr_ef, vaddr_em, elf_prot); - } - } else if (eppnt->p_memsz != 0) { - vaddr_len = eppnt->p_memsz + vaddr_po; - error = target_mmap(vaddr_ps, vaddr_len, elf_prot, - MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, - -1, 0); - - if (error == -1) { - goto exit_mmap; - } + /* If the load segment requests extra zeros (e.g. bss), map it. */ + if (vaddr_ef < vaddr_em) { + zero_bss(vaddr_ef, vaddr_em, elf_prot); } /* Find the full program boundaries. */ From patchwork Sun Aug 6 03:37:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710864 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp825929rwb; Sat, 5 Aug 2023 20:38:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE94DxPIPPYmSYMrndpkPMRv2P8benCrXHrnZEtOyKAMuMGQGkSTsDPedKswnoj8OuP5A6n X-Received: by 2002:a05:6870:a113:b0:1bb:8483:a805 with SMTP id m19-20020a056870a11300b001bb8483a805mr7133414oae.32.1691293091711; Sat, 05 Aug 2023 20:38:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293091; cv=none; d=google.com; s=arc-20160816; b=0+zQjy8OeOR+SSUmiMMI7phlI/OTSirdFVwbXC5LcdnAbWtW3oV31lVTU4OxudGqnE y6E7gkUWyBq4kERg/iDxKN7r9sLsTOalhzekrhbHK4lv//bZ6RnROKQruRu/qzyW6s/+ mgDBaJ+32pXb0G04ldbvgH0iyVJL0gKYrRbmwbyw9jV9OWq72Gg1Ve7RrmajiIxludn9 J5BiRnuvoFovX2X5zv8YTGIIKO7mENaGFz4StffHexVuSVyNwaW8Trc9oBxbTORHnKjX Enx56hsqLd1IUG6bA/SBUzT0DSlrAmqbWOSZ/eCus/hOWFsIprqK428JmBAgBwJRHdvz 7GlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lfYi3zP2whYYhdilrdAtUwTS+wOZ/T9TUKhhh0JmADM=; fh=Q92HZIlqtyucC1SOx0hVIY0BQ6aYzDDOpcVF7DuLR5k=; b=BMKJjjGXGsnMEMTIfBXhRcpnakRo20le9uibaO3d8vK+vYqzIkriWZupszk+Ra25No /C/f9tj9BJIyB26MrhZC+w4t3NOm9+Aq178oxBgzVBSxMuAtmYvLnVmii4aC03UZJweJ QKT6BQxgB7OfSibAXmxFMr4E1vrwI8ROrMUbryiQpwPytkZ4i1bUBAqBRpqJsFwGQagV GYz0SI/SgHJDdvalG1CHYtDmClnzXe+cYkomAWMRHkibqOq9LGMVkhGLfemnVsqW+Nie TyejPyv6aCY2QUUor4zOjIgsj6kQ+LolqXOqUka8hZkL27KtKhP1UvGCOmaNZiwBVxRE eYNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HdyPok+3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j4-20020a05620a410400b0076799979daasi3401800qko.238.2023.08.05.20.38.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:38:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HdyPok+3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUaL-0003lD-7g; Sat, 05 Aug 2023 23:37:41 -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 1qSUaI-0003jw-6L for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:38 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUaG-0007bV-IW for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:37 -0400 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-268128a0105so2263148a91.3 for ; Sat, 05 Aug 2023 20:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293055; x=1691897855; 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=HdyPok+35A++RKX3yC0PF7hseKukkof6kahARC9kKVXK6WUkzluMycTr6fDE6K576c RyDl2kfcDH1jczDplg9no9tNPr3DQd+VtOZ0lTq9cY26+0XScCm9Up/jqInUx5NuFhAR 7J7fmuh6TenmTm0ovFOXlg+GedT9ykcf5XYnPmglTX/92k8eWcvQyR1nAcOvUYEzUoE0 9mTI2q+jZ2IxA0GYEVOvI5NzM+mPPvFqGIlfF7IBG4DRAKrTTvKd2bukUGq+dFKFPCVj X25jz99cXiGyvhH49eS+F7qdYXHRrP9J7W8NPAYNr1fpvOmojayb51YsgyFhPMLmPf0N SoAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293055; x=1691897855; 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=WYV1ywJ/jRoZWX4eCP7aNPtS2lYxREECz7TZLxmjlNF2qWKVqjjyaXmI/42YDXHAy4 UsPkvxHfCx5pAWVK0+wDsKByOFvky+X60jzX4zytAQTejTJrsdKY3zr1JHMEhNRN4Hsi d488dYLSirPkX1cfJU7Axhh5cfDFadnIgdFOiAoESMi+LRQ7pFOWkOZRTUdLVCszkWhM EdnSr3NM1/XIA4G+mnOSzGYAK0dF7pTtqZihW+ZAsSY48NdgEiANC/Sn0D9kPQqCNp5C /ajlzYsrFa5+wxIXgWvzAyGZhqdmaT1JwpzUmz/Q5VccWQ7UeyQfL4ELu+wYjvSLq/Zo bPYQ== X-Gm-Message-State: AOJu0YzEe5l3MCBe/EeS/P/AWW7Xjv7gU2dLmR6JFKxrN/+59HC1GlNR c/VwlkcFqWQME3yHjmC83tgojt9pbxQDH5TE+ng= X-Received: by 2002:a17:90a:eb07:b0:267:a859:dfef with SMTP id j7-20020a17090aeb0700b00267a859dfefmr5281440pjz.27.1691293055326; Sat, 05 Aug 2023 20:37:35 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Mikhail Tyutin , Dmitriy Solovev Subject: [PULL 23/24] accel/tcg: Call save_iotlb_data from io_readx as well. Date: Sat, 5 Aug 2023 20:37:14 -0700 Message-Id: <20230806033715.244648-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Mikhail Tyutin Apply save_iotlb_data() to io_readx() as well as to io_writex(). This fixes SEGFAULT on qemu_plugin_hwaddr_phys_addr() call plugins for addresses inside of MMIO region. Signed-off-by: Dmitriy Solovev Signed-off-by: Mikhail Tyutin Reviewed-by: Richard Henderson Message-Id: <20230804110903.19968-1-m.tyutin@yadro.com> Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 4b1bfaa53d..d68fa6867c 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1363,6 +1363,21 @@ static inline void cpu_transaction_failed(CPUState *cpu, hwaddr physaddr, } } +/* + * Save a potentially trashed CPUTLBEntryFull for later lookup by plugin. + * This is read by tlb_plugin_lookup if the fulltlb entry doesn't match + * because of the side effect of io_writex changing memory layout. + */ +static void save_iotlb_data(CPUState *cs, MemoryRegionSection *section, + hwaddr mr_offset) +{ +#ifdef CONFIG_PLUGIN + SavedIOTLB *saved = &cs->saved_iotlb; + saved->section = section; + saved->mr_offset = mr_offset; +#endif +} + static uint64_t io_readx(CPUArchState *env, CPUTLBEntryFull *full, int mmu_idx, vaddr addr, uintptr_t retaddr, MMUAccessType access_type, MemOp op) @@ -1382,6 +1397,12 @@ static uint64_t io_readx(CPUArchState *env, CPUTLBEntryFull *full, cpu_io_recompile(cpu, retaddr); } + /* + * The memory_region_dispatch may trigger a flush/resize + * so for plugins we save the iotlb_data just in case. + */ + save_iotlb_data(cpu, section, mr_offset); + { QEMU_IOTHREAD_LOCK_GUARD(); r = memory_region_dispatch_read(mr, mr_offset, &val, op, full->attrs); @@ -1398,21 +1419,6 @@ static uint64_t io_readx(CPUArchState *env, CPUTLBEntryFull *full, return val; } -/* - * Save a potentially trashed CPUTLBEntryFull for later lookup by plugin. - * This is read by tlb_plugin_lookup if the fulltlb entry doesn't match - * because of the side effect of io_writex changing memory layout. - */ -static void save_iotlb_data(CPUState *cs, MemoryRegionSection *section, - hwaddr mr_offset) -{ -#ifdef CONFIG_PLUGIN - SavedIOTLB *saved = &cs->saved_iotlb; - saved->section = section; - saved->mr_offset = mr_offset; -#endif -} - static void io_writex(CPUArchState *env, CPUTLBEntryFull *full, int mmu_idx, uint64_t val, vaddr addr, uintptr_t retaddr, MemOp op) From patchwork Sun Aug 6 03:37:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710865 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp825943rwb; Sat, 5 Aug 2023 20:38:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGGy93pSAGoiRAQ81pvRwUdyk/pEBuIONNqqasnUO8wQ4Z9vmJcBNxDiCmJnRJx6L86aXwa X-Received: by 2002:a05:620a:458b:b0:76c:e2db:42b0 with SMTP id bp11-20020a05620a458b00b0076ce2db42b0mr6685471qkb.64.1691293095917; Sat, 05 Aug 2023 20:38:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293095; cv=none; d=google.com; s=arc-20160816; b=b17suBs/hAOPUgE0jSI9GihdrwTWYvDEwvxM3psUB8/yPQYvFDPjXA5MAzPGbWa3ut xLmx86qzKc6ClI2y3UMes7dpRUK1gtMQao7W3kn7lYfA/gn3FASxiO3HxVgT6hZDMHN9 ylJgLWc8MND3bn7YwfAhrjMALsv/Ei1YQWWiqUIpnlEBKEfm/y0mC3xr0avy+JT4zCMs RF3ap3eyh6Gb8hnD1B+Hd23Hf+a9VS8kghfM0Naa5zy17eEL0kicURBsc7jstevX+ANs YKrn2hPER12mbjtSX+f4hny+Rn9EqQVIFZGErO37FFozhnbR200OYBnXqMuThPQ83ilu tsQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=33FWwcFvaizWH4t629x3Vf1EkBPMJLEp9WeUHM35B6g=; fh=v50xmCPEMFOIbaYlDCfPzxUB5xs3fQch4cdtTCJGBiQ=; b=Vc4W4Flm6/CmdYOrL6IBQnqwSRPxHrEfMeA6rqieBFWdDre9IqlmvAw0Xde+/2Ehpw wYk/MU8+kQ6gDzXfToFJYn6TH6VpHbI0lI9y0vAz85yOE5gYMbyeiQuuonri/8q4qqLJ wGglf662/kx6ASKNHCrtz3NwEIehe1R8CXjQ+pLH+0LFb3QIpDNtFYeImNE8MxA4vB6x Y1m/qknA9s8UTmNkHpPYW3ih2y5J0hYWwnBSR/sAXgmhj3OcaI256X8U0gEBdEim1Ayt UAJPxYVFhVXEUCzUMM/0a3l5Y5qKZw8Auz5EpD0SLpA0NjVUTLB9OcKwG+PyecXjit0s Pr5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WPpUy4Ew; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t20-20020a05620a451400b0076cbce78ba0si3542782qkp.456.2023.08.05.20.38.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:38:15 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WPpUy4Ew; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qSUaK-0003l6-RK; Sat, 05 Aug 2023 23:37:40 -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 1qSUaI-0003kM-SI for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:38 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUaH-0007bh-98 for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:38 -0400 Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-55b0e7efb1cso1796283a12.1 for ; Sat, 05 Aug 2023 20:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293056; x=1691897856; 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=WPpUy4EwFwNvDV+VkrdZ76quH0WEYXHbkeIB4O1qZmLG0v/PyV0msYQHYEFI1BPsfX Sw9Fqru5r5fpFqbxd++Eiug27pEmbEUYs65lAChW1xqEN3C+m+EbsV+RHxpeBkUDYy/4 EER8NqwBCA5Ad75/Pqj1R71+7ARj8eftUKugZ7fzUjPApZX+pCmneDZbL42081GyP3g0 ByHzKrKAx3N3o41ZqFlw+IeLMDTL9xXooq0SIlJpPkGfTBkiA/vetXm9TP5LVwPQcluD iz8PGOtGWYR9MkE/j9hmvkShzq3mj7MYiTpsXsSUtnw3w9iuv+FoiD4i8bhFURGbDxkk E+tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293056; x=1691897856; 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=L7+R65djpS7u3ykdNB72yks5BciWTD1m+4KgMWP0Z+bDKcq0XNJfGy/cfYR0kZBV01 cYmIXmiT8mYOdHkT7EapuENh+VR55KC7i+hkQexZkx16D+U4uf/HVA1dpP6IZzuBQIiw kPGYI5HodSJWXYfJiuQT6eOd4Uya7HPb4ea8hVYIZ8TCg2+IT+z1pm2Y8R2S+9nIm2Ps se4/64nUCKgk8EZff3n1WDwceVcAJ1yE10iiA0AHLEQDqtBOGQlpbnZ6qNR9psTNUiu9 x0ZZzeCukGwnKFt05gMccn3WkYei5RZyH+5z2ksRhQPOGvJ7mEyv+dMvCqXP/eZlEz9b avhA== X-Gm-Message-State: AOJu0Yzd17/s+3XiFu9/crdl8d9WdQ7e43t2l+6sL23W1aZYA65SQkiR YvcUIG0cybRK+HsyGobiqVlILELuYHKPo4vkZZE= X-Received: by 2002:a17:90a:5302:b0:268:2746:5c07 with SMTP id x2-20020a17090a530200b0026827465c07mr4474172pjh.43.1691293056103; Sat, 05 Aug 2023 20:37:36 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Nathan Egge , Daniel Henrique Barboza Subject: [PULL 24/24] linux-user/elfload: Set V in ELF_HWCAP for RISC-V Date: Sat, 5 Aug 2023 20:37:15 -0700 Message-Id: <20230806033715.244648-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x534.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Nathan Egge Set V bit for hwcap if misa is set. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1793 Signed-off-by: Nathan Egge Reviewed-by: Daniel Henrique Barboza Tested-by: Daniel Henrique Barboza Message-Id: <20230803131424.40744-1-negge@xiph.org> Signed-off-by: Richard Henderson --- linux-user/elfload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 51591a1d94..c9e176a9f6 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1710,7 +1710,8 @@ static uint32_t get_elf_hwcap(void) #define MISA_BIT(EXT) (1 << (EXT - 'A')) RISCVCPU *cpu = RISCV_CPU(thread_cpu); uint32_t mask = MISA_BIT('I') | MISA_BIT('M') | MISA_BIT('A') - | MISA_BIT('F') | MISA_BIT('D') | MISA_BIT('C'); + | MISA_BIT('F') | MISA_BIT('D') | MISA_BIT('C') + | MISA_BIT('V'); return cpu->env.misa_ext & mask; #undef MISA_BIT