From patchwork Thu Sep 1 06:51:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 601795 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp249510mae; Thu, 1 Sep 2022 00:04:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR7pFQpl9nhV3b0cOf6pmlDP37VDTtoCGngNVI3TmKqnQexsXr2kfY02rrc8AklONV1VME16 X-Received: by 2002:ac8:7f04:0:b0:343:36d:9a1f with SMTP id f4-20020ac87f04000000b00343036d9a1fmr21979423qtk.566.1662015841286; Thu, 01 Sep 2022 00:04:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662015841; cv=none; d=google.com; s=arc-20160816; b=DZqC47/VJtylsDLONDw1LM0sfGfTLtKzqS7Tu1EwZ1p3BpVXNOYBhKCHF1+mRi5uIh MzlQ1J2aG6EmRG/YE14wKYrapRVdRVAZRx0oR6Zv6bXx3ZQyG8+g++sN240PUixmJDCn 3X6eijktSvEGJZFntsImZCpUd0Z9ediWzJxUesKIaqO30jLfJZJy+V9GYxrQRwWiztIm 5rxomyEAhiFRWLCUH45jTeuUGGGk719leCKfnxWQO2pv0MKsnBqR/JzJ5MMSatZMVWe+ 89PSDrLLofqJO6LwIEVdTXk/Ey6USZg/vSDLP7bQVMcMt/MNzEjBF9t1zeGf9UrLNRuZ B1pA== 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=VZcN36zLYSVB9HNzHbBnLu3lixDkXE5oh/PEqGuZ1vO+aQY0XK1TF7uXEXwMZtW/dm cJVVLgVkmshXpK/sk8QlptbQQFs6fdnjmvTU+Vw1ck1O7q1/fDLIODdEESST1D1gWNS0 T0e6bKDqmzzqMRvh+InnUukb1hWOh9xivI1sI5ERq3ISRVZe0Wl46jQmFcmYhVmy74/M zgTcJcfQ97eVgi+H/sMxR7/miLbcztJHTrrpfaRwN987urf/w2iGWaOtgcC5yO1dmToQ sl/mpWtm2gCliTD0uC9dSnKk+IZonEFslACt9Khp8bVKWhc3+ti384tAalImL7WQhqqX rW0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HQfoTiO5; 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 br39-20020a05620a462700b006b8fc083ef3si9684516qkb.68.2022.09.01.00.04.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Sep 2022 00:04: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=HQfoTiO5; 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]:38498 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oTeF6-0003fK-Pi for patch@linaro.org; Thu, 01 Sep 2022 03:04:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59112) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oTe3v-0005s7-MO for qemu-devel@nongnu.org; Thu, 01 Sep 2022 02:52:27 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:43685) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oTe3t-0003GR-Vn for qemu-devel@nongnu.org; Thu, 01 Sep 2022 02:52:27 -0400 Received: by mail-wr1-x433.google.com with SMTP id u18so8341642wrq.10 for ; Wed, 31 Aug 2022 23:52:24 -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; bh=+TkWIdFQsuVrBlz1iMZEZBv2Eng982tGzQv+UxtokKc=; b=HQfoTiO5xIrT302HofUFO4RioFMFKKBINHO9/6/a34Nv9+SbpPGujeWNAmuSmg90Cw tAubLWzbsHFbdUU5l8RoYjR0vP5SjWBR5ZiMl/cG25D54JXBpej9HE7kPRrJZCizrooB zsldSeE4BOwvHaUbpj3cqLHHADLdSD3H9ewloX2c+KkmLNJNhyBIBIZWZeaP7vid8ayJ /gS4nd7ZpPDkmaaqe1rrO9iUElMRq97VLv7hUlJnSCLgJ1PUBGgoRzLntuHqFWdpHsEG yeA4vXaACEUeZGG0TSmaGYDULU4FX3fItJG8dcEwOB1K6IzEdOQo8HJRXLXjzIO3QGzc hRDA== 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; bh=+TkWIdFQsuVrBlz1iMZEZBv2Eng982tGzQv+UxtokKc=; b=BrRrYx8FLPrYSgQJ2CV1OoQtnmLGeRzr50cl+bnsFIBS9ukrFAMLc4x4LLensdcai3 BsMZjoCn9hX1vrbXThA2YFambXV3cc5ysQizNmUN72vYIPMeRo6t7SSELD0/gNt3dAz6 vUbKglhUmCwX9BiYPDR7x+MFrtCuuWuugKi2seTxyERUoVkeftt8hgecNET5Cr1Ulu1Y XlmutSF/pwk8tYlI5WG7s/oiX8UY9RFYrRhX1hdjZpw83DoA556kkk5Sko3n7rrfz6Zt zEyjeudsIeAlKWZx8dFMkSjsg5vePEMtFdMewoZ27SB9gr/ugIqtLZGEdg1usOFMOGct Z8Cg== X-Gm-Message-State: ACgBeo3zoQqkeYgrRwEVcFaio77lKah57Kb5c3XoD7KikolHwHhnCvpI NN3Dqt6FyK81/HH6q7kxNmhAFpHNjx4lR4Tf X-Received: by 2002:a5d:64e9:0:b0:220:7dd7:63eb with SMTP id g9-20020a5d64e9000000b002207dd763ebmr13502698wri.590.1662015143275; Wed, 31 Aug 2022 23:52:23 -0700 (PDT) Received: from stoup.. ([87.192.221.83]) by smtp.gmail.com with ESMTPSA id a6-20020a5d4d46000000b00226dedf1ab7sm8308153wru.76.2022.08.31.23.52.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 23:52:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich Subject: [PULL 02/20] linux-user/hppa: Allocate page zero as a commpage Date: Thu, 1 Sep 2022 07:51:49 +0100 Message-Id: <20220901065210.117081-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220901065210.117081-1-richard.henderson@linaro.org> References: <20220901065210.117081-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x433.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); }