From patchwork Tue Sep 6 08:37:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602952 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4332199mae; Tue, 6 Sep 2022 01:44:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR6rMRnysbR2NceBkSNQWyWxYDzyHgnYLrILK4X+ZR5uv6FCllEtW47w7XLQCjHzb47F3ch3 X-Received: by 2002:a05:622a:5cb:b0:344:551a:c804 with SMTP id d11-20020a05622a05cb00b00344551ac804mr42410997qtb.645.1662453890850; Tue, 06 Sep 2022 01:44:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662453890; cv=none; d=google.com; s=arc-20160816; b=jyJZC94/zxLdveQr6YUl/mYgldXg6dFcZ240jovv6MekWWajVDxXgf/AE7SU6FPjnJ ZQn1ERqF5GppTshfB/d7GpPMLYldqNW//oP+h1T7HBGPeAQnYk6pSbhfXGOgsTuhNTg1 z01PFLAbv0h9ayBwjJK6N/4qi6jsmS3pkrcH7Ykdry3t12vbuZEJ7XqRvAxbgft97HZI ve/bxu00eN1p4jicRQabWk8CxkJUu6MTXUCfBoAYprzS/eTaV7WaCstD4qfMabnu+NNB 6gqLITRjyesw0+6/WVKQGS+c+K6vgNHR5kA6e2ge+4v6WoIdrViY7bHKRmIPfOTfLOR9 s1fQ== 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=+TkWIdFQsuVrBlz1iMZEZBv2Eng982tGzQv+UxtokKc=; b=sGKAerUGOjKAH1G+/YEDfNGRHuDj7sfci9zqkDk0WmmFmCPnqk8yn6euxk847dR5Y+ d4s936mSfcpXvvBt37C1b16FUkxOjSJsaZ5yi/VLzTZ+fROqq1vyYnpI3WoD1oXCbnZT 7J0f2YXgU2qst4oG12VD8LPZIAW0DsqQrCQA0etCK6bnMJ6J9uYYlbmxrXJhtTYfNi8S 9PeywYA5gu+TD/npOwjZHenxSrMfCk1SRcEjrI6BevjujgJGv/pIeeElrT/MOYe5Jqwd T4EbL2UHrVWXpKIrUgVjoxGU/Dv0XrYh65Kt5b0Q0rfX0s6N7SyYp6eOEPsaDeE8gg+H KD1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wB0mgkER; 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 gw2-20020a0562140f0200b00496ce50efa6si6818755qvb.586.2022.09.06.01.44.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 01:44:50 -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=wB0mgkER; 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]:33308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUCQ-0008OK-Ce for patch@linaro.org; Tue, 06 Sep 2022 04:44:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6D-0002Ur-I6 for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:25 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:35569) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6B-0005Se-Dg for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:24 -0400 Received: by mail-wr1-x42a.google.com with SMTP id bz13so10891606wrb.2 for ; Tue, 06 Sep 2022 01:38:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=+TkWIdFQsuVrBlz1iMZEZBv2Eng982tGzQv+UxtokKc=; b=wB0mgkERKPGGxWQSodB1/D1shzl9Fdz57x52C5TOrnTOCF05wSo2ecVXXMAgYQiMyo 8L/wiqmV/xgs3tVS9P7Qeh5AJDFgOCTo75F9gjuERSHerMbcf1RHcOz+rKSkizmAXH3Z 2GUjCCn3eDycHaUGO/n5vUtxQ0Ffmj5kD2tDasS4DEggHVI1gYISBtz/kjhLzUJG+wDD HhdNVqFNq1CArhZ1llhAs5B1PAVd9UuKXYXoCa6oW2KgSijMh419NtqoUZ64HW5P3JyI nT3bDABxmDxWGXo/M4u1hoXE0ahuETQ6bc0088gxSabV85jciWL+tsVGFeI8lufwEIan rzrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=+TkWIdFQsuVrBlz1iMZEZBv2Eng982tGzQv+UxtokKc=; b=iH4qMrumzIw6MZIwmPEcaInYP+RHbWMTDYcro3lo+uU6AoHQfYeZ3VU6+XeyOq6Vz3 mlFZhGqkYhCayOuPBgU1QRvmK8z5wJqIvtJFTMv0cBaMtWo2VN3qlLyGNPVs7mePTAUr gGwi9r/1j3aUAtYTrXY00Btz2Tqhm4bORyaqJZRU4NIea0DLT1r1DMLbWQ01o1COqw3m UwgGMIK2CSWrpqFci2+NfGQc+qGTfVjpbCk6Xu3QH9Nj/HcVMvI3XvGNeBA7PNGRE8XZ XuyNYISf9FEJ8ebyRLRPBe3EaXXa88mEECa9Dzd8kM4SX+2+2vnypUov3JRGs6yjyXh/ K9/w== X-Gm-Message-State: ACgBeo1CuSEBDKHuIC8fxp8qE9Qj1QUwtKoxn/MSOrX7scwl39IHzKtV 3ytHrKnKXy9D39EWYsoDS2it6IEi7KSNjXam X-Received: by 2002:adf:a447:0:b0:228:6ee1:135b with SMTP id e7-20020adfa447000000b002286ee1135bmr5703721wra.6.1662453500496; Tue, 06 Sep 2022 01:38:20 -0700 (PDT) Received: from localhost.localdomain ([2a02:8084:a5c0:5a80:ba98:3a71:8524:e0b1]) by smtp.gmail.com with ESMTPSA id g26-20020a7bc4da000000b003a54f49c1c8sm13421859wmk.12.2022.09.06.01.38.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Ilya Leoshkevich Subject: [PULL v3 02/20] linux-user/hppa: Allocate page zero as a commpage Date: Tue, 6 Sep 2022 09:37:57 +0100 Message-Id: <20220906083815.252478-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220906083815.252478-1-richard.henderson@linaro.org> References: <20220906083815.252478-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We're about to start validating PAGE_EXEC, which means that we've got to mark page zero executable. We had been special casing this entirely within translate. Acked-by: Ilya Leoshkevich Tested-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- linux-user/elfload.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 3e3dc02499..29d910c4cc 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -1646,6 +1646,34 @@ static inline void init_thread(struct target_pt_regs *regs, regs->gr[31] = infop->entry; } +#define LO_COMMPAGE 0 + +static bool init_guest_commpage(void) +{ + void *want = g2h_untagged(LO_COMMPAGE); + void *addr = mmap(want, qemu_host_page_size, PROT_NONE, + MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); + + if (addr == MAP_FAILED) { + perror("Allocating guest commpage"); + exit(EXIT_FAILURE); + } + if (addr != want) { + return false; + } + + /* + * On Linux, page zero is normally marked execute only + gateway. + * Normal read or write is supposed to fail (thus PROT_NONE above), + * but specific offsets have kernel code mapped to raise permissions + * and implement syscalls. Here, simply mark the page executable. + * Special case the entry points during translation (see do_page_zero). + */ + page_set_flags(LO_COMMPAGE, LO_COMMPAGE + TARGET_PAGE_SIZE, + PAGE_EXEC | PAGE_VALID); + return true; +} + #endif /* TARGET_HPPA */ #ifdef TARGET_XTENSA @@ -2326,12 +2354,12 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, } #if defined(HI_COMMPAGE) -#define LO_COMMPAGE 0 +#define LO_COMMPAGE -1 #elif defined(LO_COMMPAGE) #define HI_COMMPAGE 0 #else #define HI_COMMPAGE 0 -#define LO_COMMPAGE 0 +#define LO_COMMPAGE -1 #define init_guest_commpage() true #endif @@ -2555,7 +2583,7 @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr, } else { offset = -(HI_COMMPAGE & -align); } - } else if (LO_COMMPAGE != 0) { + } else if (LO_COMMPAGE != -1) { loaddr = MIN(loaddr, LO_COMMPAGE & -align); }