From patchwork Sat Apr 1 04:51:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 669417 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp843982wrt; Fri, 31 Mar 2023 21:52:01 -0700 (PDT) X-Google-Smtp-Source: AK7set+7Wtz0FCLZ2P1usLir4fPRT7B3Yuo2lyz5qDhJX9L5l4EDQwsvB9cgZKDkuZpq2lP6/R6e X-Received: by 2002:ac8:58d6:0:b0:3e3:7e6f:423c with SMTP id u22-20020ac858d6000000b003e37e6f423cmr51082755qta.34.1680324721301; Fri, 31 Mar 2023 21:52:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680324721; cv=none; d=google.com; s=arc-20160816; b=zAuzMHbm10dFXfa39+eBSqYqGU/SBXFSIQGvuDTUlSi96dcXzPnHs6/JEg9NlSmovt JEpFhBbtgDzYZCqYA60wrsj2aKZWx+tlCHY0McCniZbkZfDQLOPPbn+U+rIjOe2OuHdS 2mXumZsTV3BF+4PoyTptvVOeeHmBA8iUrBHXynFTrcgiugd38lQ8AaBykVXS8vxueiOa N8V7T3cpmAgQkUV1zXC+JWjrUwjgiEJC2U+X7HIO+x8Ea7d2IHnQSFXuDysjunQgdgZX 14XTmHOIorNuONq2Uc/+Ru1a711wEm5GxoKj5rajf1J9GjeyfA6Fg9sKZpTeuWLhvRPq 35oA== 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=kiULY7hI3dkf5M/9do5JIhSCZ7Y5eX3RA+ervNTgBK8=; b=mWCEk9Bl50j18esJYdFjnDytJ+3cSX7lREusWObZOodn7LxSNbaq/depVivLA6mVXX ZY78hUhn/VwPy7NHM5RoaIKhhWxZ13LWfcTLgLkqTuNncHxO/KJVRYtVrT9NYaQB9T+9 3V7VBHq12xgNCIbvh5xc1BZqfD3MZ1AwnIneGILOAmwzbi4RkHu8NW06OG3oNfpCYH7M lLWmmQi8URYPcfaI9msUwwIrj6qMKEhuhDmUp85Wvvs+EpDSHtYrxWOYTJh7eiHu1mJ3 mekuDRhQdPF5h9RKEsCUg7F55CsTQtST0buH4RoI8U/eOVcT3fCXPy2y3GZYbuy0v3Xp B57Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UDg0lR/0"; 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 br7-20020a05620a460700b007468cbaaefdsi2889052qkb.378.2023.03.31.21.52.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Mar 2023 21:52: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="UDg0lR/0"; 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 1piTCw-0003rt-24; Sat, 01 Apr 2023 00:51:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1piTCr-0003qh-RZ for qemu-devel@nongnu.org; Sat, 01 Apr 2023 00:51:13 -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 1piTCo-0003Nz-8c for qemu-devel@nongnu.org; Sat, 01 Apr 2023 00:51:13 -0400 Received: by mail-pj1-x1032.google.com with SMTP id p13-20020a17090a284d00b0023d2e945aebso10093630pjf.0 for ; Fri, 31 Mar 2023 21:51:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680324668; 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=kiULY7hI3dkf5M/9do5JIhSCZ7Y5eX3RA+ervNTgBK8=; b=UDg0lR/0pRSWX6TCc3shno0pfhNggxNqN1QEDq07xnQw6ZMGtnLm/mv734ZFMtgDIN avPhobF60hxnm6SzZBWxZJetWN1ZzkcW6qbdzyHERDeNxD3IXGJ+a0glO2Xruq2p7kCC ZbV2S+ceF3WZs984DjTuByQrA5Ct0Su72tOQNkZoGmZeajPJJ6mval0KTJXhM0yyHgfa p1F7XOtdOnIGlwz9rONx3jYmZlHIi9s8ocw7nx8tKIyALxBeHjS09oD9ILwSiMDGd9HO 1tLihRcpCiNVq808H1/BQQm73EHJ1v+i2T0LMDHYRoxELogXK8YHRqkBFV8CZ92CEJTo fEtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680324668; 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=kiULY7hI3dkf5M/9do5JIhSCZ7Y5eX3RA+ervNTgBK8=; b=otlSPiaFEpRMcwyYVVgnUqa3dM10htTDANmVkb6C6L5An3DESa6JTDTfKRmcd76xl+ ovGUbc4REUYPQhABCb0a4mDwIdk1QNF7xrpihf+kygEGtCNcJI2GSXypD3RY7GP3Y3Va xdMfK7AZpcHKn/G+okBlIXVv1Z9GJL8OMa4lTxAaOaRtIy+FAyB8hUNelXwrWB4MkwDg j/BmHj9kLDcVQpO5ZSrGXY1QiyMa41L/YfpviqF/n/mASLeoEw30LfPBdmhQwbQl7YA3 ftScGaQNtsJ9vQHugt/pL7sKHIWFu6jlSAZzk2TSrQu0u3pIdRE2iyLMUYOcPB3zXAgT ypNw== X-Gm-Message-State: AAQBX9cKpU1UY577KHR4d02CMQlV63ZOm3kek5otWllMKTQhoZvUqpPB HkqkV5ebwZgP+Djv/jnwY/B1EOPCWjlmHztfNek= X-Received: by 2002:a17:903:1d1:b0:1a1:ad5e:bdbb with SMTP id e17-20020a17090301d100b001a1ad5ebdbbmr38676830plh.36.1680324668564; Fri, 31 Mar 2023 21:51:08 -0700 (PDT) Received: from stoup.. ([2602:ae:1541:f901:b714:1fce:85fa:2fc7]) by smtp.gmail.com with ESMTPSA id a17-20020a170902ee9100b001a24cded097sm2360122pld.236.2023.03.31.21.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 21:51:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 1/3] Revert "linux-user/arm: Take more care allocating commpage" Date: Fri, 31 Mar 2023 21:51:04 -0700 Message-Id: <20230401045106.3885562-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230401045106.3885562-1-richard.henderson@linaro.org> References: <20230401045106.3885562-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 This reverts commit 4f5c67f8df7f26e559509c68c45e652709edd23f. This exposes bugs in target_mmap et al with respect to overflow with the final page of the guest address space. To be fixed in the next development cycle. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- linux-user/elfload.c | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index b96b3e566b..f1370a7a8b 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -423,32 +423,12 @@ enum { static bool init_guest_commpage(void) { - ARMCPU *cpu = ARM_CPU(thread_cpu); - abi_ptr want = HI_COMMPAGE & TARGET_PAGE_MASK; - abi_ptr addr; + abi_ptr commpage = HI_COMMPAGE & -qemu_host_page_size; + void *want = g2h_untagged(commpage); + void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); - /* - * M-profile allocates maximum of 2GB address space, so can never - * allocate the commpage. Skip it. - */ - if (arm_feature(&cpu->env, ARM_FEATURE_M)) { - return true; - } - - /* - * If reserved_va does not cover the commpage, we get an assert - * in page_set_flags. Produce an intelligent error instead. - */ - if (reserved_va != 0 && want + TARGET_PAGE_SIZE - 1 > reserved_va) { - error_report("Allocating guest commpage: -R 0x%" PRIx64 " too small", - (uint64_t)reserved_va + 1); - exit(EXIT_FAILURE); - } - - addr = target_mmap(want, TARGET_PAGE_SIZE, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); - - if (addr == -1) { + if (addr == MAP_FAILED) { perror("Allocating guest commpage"); exit(EXIT_FAILURE); } @@ -457,12 +437,15 @@ static bool init_guest_commpage(void) } /* Set kernel helper versions; rest of page is 0. */ - put_user_u32(5, 0xffff0ffcu); + __put_user(5, (uint32_t *)g2h_untagged(0xffff0ffcu)); - if (target_mprotect(addr, qemu_host_page_size, PROT_READ | PROT_EXEC)) { + if (mprotect(addr, qemu_host_page_size, PROT_READ)) { perror("Protecting guest commpage"); exit(EXIT_FAILURE); } + + page_set_flags(commpage, commpage | ~qemu_host_page_mask, + PAGE_READ | PAGE_EXEC | PAGE_VALID); return true; }