From patchwork Tue Sep 6 08:37:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602953 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4332263mae; Tue, 6 Sep 2022 01:45:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR4dcFChaMW6vs2AjX85DFSmhRPjs+IbhVguvZJpay4tlmCP2C8K8Enj0Nu0Vf4OTe2d4Yb+ X-Received: by 2002:a05:622a:105:b0:344:f85d:f19a with SMTP id u5-20020a05622a010500b00344f85df19amr42259745qtw.49.1662453899903; Tue, 06 Sep 2022 01:44:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662453899; cv=none; d=google.com; s=arc-20160816; b=driwRfNr2i5rO9JjKdw4b+757X8okvfSN0BRhMKEuA493mFxCDZ99OQmb3PsK7QhTq rJJYpY6tKX2ckMqFIb3nIZFvJ3aF5zWOchqZvK2/YjvjwIZ7Ry4sCSIm7SfPva+XcgQD WHnnHiN4FNL+G5Su4Jk9MZ+LwjLly5cheam50dcQr9HSydnyLPlVvsTSt6AQahqdnZSQ q/8RzcH2h5u8Ua2PRBCul1RzPUeCKVOT3F8H8griEK1Jaa2rIABMHYf260Q6s6oMTrG/ rksU3/ruXHuuSCMYelZk4BNRdYEZbZGt6nF931jBptd0I1VpDQVizzNKsdv8LILAhilJ 8tkw== 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=cnDX4PL0OXe9dOqXgYaSV2oqzwR9gOMv9I1pf97HvaI=; b=oaymMU6JnTynN8r7uyM5+KCeypFujUts2nkXmXRSDUXqiF++AtJHCucfh8X0nmlTT7 RF0amaUVK7ZJErhOquphJt66q7+9xZhtuwcq2P33aoN/71lVTq8gXWVHlTLRU0VS7Xtn 4TMQp+DLz1ABg1Bo5nT5p7pvd9QbiPMbISrEOK8RKW9IAqvpwVr1MGG22yTD+LLXt8hZ f0AG6DbHEDFL4idBOZbvQU23EBJVe6esUFxSkPcptTYo+LEPUIQaR5vOr5z2eZBA/F1T QxIviUYQRc2hC1HcsHdujKeRxj1Ou0SkfgzgiXUkibowDky4FQDhnGrVdpP4RrOxxBni oUTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NgeEloTq; 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 8-20020ac856e8000000b0034464ae76f5si7053918qtu.511.2022.09.06.01.44.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 01:44:59 -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=NgeEloTq; 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]:33312 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUCZ-0008V8-Bg for patch@linaro.org; Tue, 06 Sep 2022 04:44:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6E-0002WL-Na for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:26 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:35577) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6B-0005SS-Cg for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:26 -0400 Received: by mail-wr1-x433.google.com with SMTP id bz13so10891525wrb.2 for ; Tue, 06 Sep 2022 01:38:21 -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=cnDX4PL0OXe9dOqXgYaSV2oqzwR9gOMv9I1pf97HvaI=; b=NgeEloTqPwZf/t80BWHoQOMnEcmH//X/4Nwx9ugY39wAiJoakPz5alQTk3xwBmsb46 DrzCKt1/o1RrIuuvgdBt21z4d2WyPasswSrPL87LP2iycNV1vqBT6j+M3SbVaaDkEwN6 BgXB4mDiROEc9Hk0xvQajrP11zBV69bbNpTIf+f+sDZ8E5p7GdGujn6HykHWEBycsZjG dtd4OyFGJBWaqsKs561Id6peOeg/vo6P4iXDnWBhYiNhdhVWAkI1baHaG1LIWZjAG29v kAaFfbh35b1JizmEJ+9ZxXz9GDcGDc0GfrxADEksf6sPsCTHbeVSVsgyQlG7ECYHXfC6 ssSw== 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=cnDX4PL0OXe9dOqXgYaSV2oqzwR9gOMv9I1pf97HvaI=; b=F5uTmdxGvWdDAFhWQ2qtU5H7oqKHYX9Zlb1lh9ddDjIHKQBd3FXEfZrJa98nTe12Uj y3n9NQaGd99b18webHBzoX4w7Y6l1ZeAjeI4zkZzfdEh2BSsOWCBvtpKKoJc7NkjyHNV GpDrfWzgBBT3jca/rcIwo6v4/mRVMnta9+Pd76mnA4bOjfLGH66KnXJmT3fo8CHcH4ZY FFZBMmf/u1y7UBB+Nlwpuy8XitqJx/n+GLH68aCZ9utTQcAZ5RdwusYDJL37ySofTYwx TFTGX/S/DlfIwb5Hu0u7k4o+Ck3sBm83uJe+jP9kpBTGf+02lTq8qPPfXgZXelt4f1O4 yLxQ== X-Gm-Message-State: ACgBeo0rqk0OLVrybknWMH2bap5rXCLzwxybzx9v74DnovUCz4eoJLPx vsusNOZDwiCiHA+k5EwgIQzd7Rp79NJ/o3Ki X-Received: by 2002:adf:eb02:0:b0:227:1c:e760 with SMTP id s2-20020adfeb02000000b00227001ce760mr11614874wrn.635.1662453499252; Tue, 06 Sep 2022 01:38:19 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Ilya Leoshkevich Subject: [PULL v3 01/20] linux-user/arm: Mark the commpage executable Date: Tue, 6 Sep 2022 09:37:56 +0100 Message-Id: <20220906083815.252478-2-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::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 the commpage executable. We had been placing the commpage outside of reserved_va, which was incorrect and lead to an abort. Acked-by: Ilya Leoshkevich Tested-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- linux-user/arm/target_cpu.h | 4 ++-- linux-user/elfload.c | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/linux-user/arm/target_cpu.h b/linux-user/arm/target_cpu.h index 709d19bc9e..89ba274cfc 100644 --- a/linux-user/arm/target_cpu.h +++ b/linux-user/arm/target_cpu.h @@ -34,9 +34,9 @@ static inline unsigned long arm_max_reserved_va(CPUState *cs) } else { /* * We need to be able to map the commpage. - * See validate_guest_space in linux-user/elfload.c. + * See init_guest_commpage in linux-user/elfload.c. */ - return 0xffff0000ul; + return 0xfffffffful; } } #define MAX_RESERVED_VA arm_max_reserved_va diff --git a/linux-user/elfload.c b/linux-user/elfload.c index ce902dbd56..3e3dc02499 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -398,7 +398,8 @@ enum { static bool init_guest_commpage(void) { - void *want = g2h_untagged(HI_COMMPAGE & -qemu_host_page_size); + 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); @@ -417,6 +418,9 @@ static bool init_guest_commpage(void) perror("Protecting guest commpage"); exit(EXIT_FAILURE); } + + page_set_flags(commpage, commpage + qemu_host_page_size, + PAGE_READ | PAGE_EXEC | PAGE_VALID); return true; } 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); } From patchwork Tue Sep 6 08:37:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602950 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4330287mae; Tue, 6 Sep 2022 01:41:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR7jzJLYtRO0NgSmztkRpX2GO245D/X0Dqm/iOEAo2KrGxBAuudXytPQEbcUfOuMYzjwtBcF X-Received: by 2002:a05:6214:29e6:b0:498:fe79:9095 with SMTP id jv6-20020a05621429e600b00498fe799095mr38469783qvb.49.1662453680565; Tue, 06 Sep 2022 01:41:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662453680; cv=none; d=google.com; s=arc-20160816; b=RHzlZxAr/HPYxhM9RmVeH31cu2ff99JzJXe68+oeROim/IKq1JMsbXm/pp3xCugJvw cZPPmuNjiiWP5msGLVl8PeQ8x8lUiDHoit4OjIYCaKWE71Jf9CEv7bjm0DLqDL659oJu IFqeTJS82x7ghCiP8EBJcduuLBa+tm1brUPgi2UrLe6FV/iKrpoIc/v9HwzMtKdJrYRK i7eZh1Rdx9ZuKKFTLkebAGh9ownKE/7G9MRcoTNszH0osb2H2c/OXMuhfHn97D2o3yss oYXkkSV7c++K0L6nyBidJLl7SAj+i8CSsOYMBgNdRIAbvPi2ZVQi+gbcEy3X2YMc4vb1 rVjw== 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=KgHC0Epmn6vIL/++u2sTVzw0n1Bos8TAPXCVOYM1ynY=; b=h0fK69dOtK4gktdjSUSUfBnsdWTBwyUN+DTseJhtP+qhKoem+xARuJXxIO4bX406wT xZZxt65T5Fbf2BuvL9gPYB+qG3Ki8rR+6bNbnZQtE0noClghbew2Yh2cQ9yjc8nxeHWO EM+8wn7tbsRM24Djzhif7t0M9lBRTFM+uxtcGSXStGqpaO8fmWED3t2FgKh5CWKXOb88 5iKJES3xrE8BTsMI3oB4VJrlMTBu7INqFWDCVfRL+CtF4UUAZ5DW1G/rkzzhbRKDZGP/ ZaUza9JPz60FWoe0mA704qTlzUdAKJNg3oacNPcDlZ9OhHYvEkjhAeETeCaXHlUsZmhB /U6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RDKjCRAy; 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 r4-20020ac867c4000000b0033f9fb199dasi5933729qtp.324.2022.09.06.01.41.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 01:41:20 -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=RDKjCRAy; 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]:51220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVU92-0002Xl-5j for patch@linaro.org; Tue, 06 Sep 2022 04:41:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6D-0002Ut-Ip for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:25 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:35570) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6B-0005TS-E4 for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:24 -0400 Received: by mail-wr1-x42b.google.com with SMTP id bz13so10891652wrb.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=KgHC0Epmn6vIL/++u2sTVzw0n1Bos8TAPXCVOYM1ynY=; b=RDKjCRAyh8eFvcPmfcdflwD8QPeR5U5+6Y63s9VK2Y7KAVQPDXqskMp4+Kun6VwHvd x4uITsj2v0QdLI0j+Bl/AI+be6fSaFwXCJ513NPDYLRaVuBsw/ynB7oYejLEfVa3IgP2 xynPfdpyrmQ2QJJ1VtadgVOyAe3zt/IHm1gEOVzELu6LKSvrc9GonQlg7Nmo69YdL799 eQVZ2H2DnDiYgBdc6+CHB0u5HahRcFE2JIKE+MAWvYjQ8X4DxrNNQb6y/OzhY7VLS4bR qHJ8ArpbKsP3azVe6ht3L2MmeYJk6f1V0nnoOIciyEQwTX+VO4R7VTftczAg2dA+GktJ O5Cw== 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=KgHC0Epmn6vIL/++u2sTVzw0n1Bos8TAPXCVOYM1ynY=; b=1DAoonMEIZapbXYMIcQ/Jdk0l3Ex26e5C+864qV123gsONMD1Ey4IrefsdHcfL6YAx zJWoUb3JGtgqf+GLkVIVwKhZGmqdYIyzug6kJ9wkcFpmHuo9wzkHUO2xSBo4a7mX2/mi G+Gr+oJtuXIo29Qu5Ca/9b96Robk6l4ZVtUT4DzYmb4GZEtqvw6oEKldXDdO47szFhaH RsA7HCU1bDtDukyxsl2MKcgphID60TnvIcDxcNodo3kwFbH8pWqs+/5Vx3SthuPJ6xKQ aoIbDj7gvVp2fRo+88lIk18lqib8d4cQQfK6ehajFqPIL25vU99r6eG8kcBosOgcp7dj gHMw== X-Gm-Message-State: ACgBeo1pg4+0c1O9//JPeYAv7iNB1CmAPEeUjxk4zoC3jxbXuQ/anAAG JX1JXXmboIZ+tJGjxqPagcZHT4i1cOLKL5uE X-Received: by 2002:adf:efd1:0:b0:226:eb1c:de82 with SMTP id i17-20020adfefd1000000b00226eb1cde82mr16120224wrp.81.1662453501488; Tue, 06 Sep 2022 01:38:21 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Ilya Leoshkevich Subject: [PULL v3 03/20] linux-user/x86_64: Allocate vsyscall page as a commpage Date: Tue, 6 Sep 2022 09:37:58 +0100 Message-Id: <20220906083815.252478-4-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::42b; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42b.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 the vsyscall page 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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 29d910c4cc..82fecf9e5a 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -195,6 +195,27 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en (*regs)[26] = tswapreg(env->segs[R_GS].selector & 0xffff); } +#if ULONG_MAX > UINT32_MAX +#define INIT_GUEST_COMMPAGE +static bool init_guest_commpage(void) +{ + /* + * The vsyscall page is at a high negative address aka kernel space, + * which means that we cannot actually allocate it with target_mmap. + * We still should be able to use page_set_flags, unless the user + * has specified -R reserved_va, which would trigger an assert(). + */ + if (reserved_va != 0 && + TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE >= reserved_va) { + error_report("Cannot allocate vsyscall page"); + exit(EXIT_FAILURE); + } + page_set_flags(TARGET_VSYSCALL_PAGE, + TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE, + PAGE_EXEC | PAGE_VALID); + return true; +} +#endif #else #define ELF_START_MMAP 0x80000000 @@ -2360,8 +2381,10 @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, #else #define HI_COMMPAGE 0 #define LO_COMMPAGE -1 +#ifndef INIT_GUEST_COMMPAGE #define init_guest_commpage() true #endif +#endif static void pgb_fail_in_use(const char *image_name) { From patchwork Tue Sep 6 08:37:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602956 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4336695mae; Tue, 6 Sep 2022 01:53:11 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Rlu7PqymR/3GvfnzBAzXbt84f8VBC9+40mxjN19IYiFJ8jy66M27x286CdjfhZWaNL1AF X-Received: by 2002:ac8:5d89:0:b0:344:7c2d:92ba with SMTP id d9-20020ac85d89000000b003447c2d92bamr41418205qtx.124.1662454391841; Tue, 06 Sep 2022 01:53:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662454391; cv=none; d=google.com; s=arc-20160816; b=UTX95KQRvhN8tx8jOm6zQweK43DOj0oeeWx60FGuR2tyWZ5mihZkCGoLweMePQg9Jg IpwiGRwj7jc6Kw+CUnoaooXiRfAruMv/98bdlDssce3rUKR0MGvmDKvRTzBxkv256w+h XIUUpB3sJfZvAvsMSJ0dsv6rfGEzHpzFVxBamPJwcjCXeTq1Y+WJJ78vMgjziAInGWWH PX3ORqHRZ5ivwKpRYejsaW2yiNsrj4vHRCDhHTT6hsCzP+Tk7S4Tte49whKNCMUAuQhn H/vtW+apx4XTn3csFUD5jrsqtdWqovH9gjoRppGWCpTnOXgAw7475lphJuyg63v7SS2A S5vA== 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=yHZSJUz7LSiy8DsABftVDyRV2Yzcw9MuxBIikIfZ3SI=; b=Vbg0ILWAAdm+M7YP5/4EFc3y804ziM5G0EtGsRSPOzHettvB0LoCK+CRydAM/1EMUD x4cUS8QFkT1eEeTEXILgCdd99VGIJT4aCed5SU179sLXvwiT62Qvh+sPwq5G6sUzMroI y6c806cVC8GpbNnQQkbMhDiyu/Z3n50I7EhaqxgkpAQZdjL/oDOAEGtFRtWQSf2roIbd toEybi1zMGuDVoeltWI/cX2Kx2vph+hEkE72e7kj4U7ONU41i9i4DLgAQa9AAxiCwBsW eft3pfInKLm7ZSXnGa0o1nr+cbV8vLz0yz0sZIN7z9MthGmIi15uEZee4wi2pL3CZEZn ibeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=niPafJe1; 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 p20-20020a05622a13d400b0031ed7081ff9si7826427qtk.550.2022.09.06.01.53.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 01:53: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=niPafJe1; 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]:55200 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUKN-0005uC-1Q for patch@linaro.org; Tue, 06 Sep 2022 04:53:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6E-0002WO-W5 for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:27 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:38810) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6C-0005U8-7K for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:26 -0400 Received: by mail-wr1-x434.google.com with SMTP id b5so14309385wrr.5 for ; Tue, 06 Sep 2022 01:38:23 -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=yHZSJUz7LSiy8DsABftVDyRV2Yzcw9MuxBIikIfZ3SI=; b=niPafJe1OZQ+Pbfn1LJsWMtUbQqafVY95ERZATwVGXuyLPfeF77OvF0IMmaFsAl8xG AwsTtshkb70WtzYxhVcvxS4PJVsT4IAbYeoOJejOekOJGBEDLh7e600TkdnfrKCDF8oq pSXPUIgLLjEN28x7cqMXFq9hoEPyfA2CqKO0VfXEIKeEZbN8XrCHu49VzzwqQZYPSsix XcH56NnpqN1F5hCLVskfapXAURa1266ZxXiY2q6JnPFF6GVnldYNEiU4rMcqGR1BiBQU YIVXQy0MNTVtQASeyggKbkz2ED5u0ype31COfC/ADJolcP86fqmyjS0qG9hZdGa/aT1j KuBQ== 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=yHZSJUz7LSiy8DsABftVDyRV2Yzcw9MuxBIikIfZ3SI=; b=G0hxjy57G6UFSkTX6p2j7jNs3TN+Ndl9cZw4G6KKAA9G9BeZfLj3pKUa2Oi78qsAQM djwDg6/Ibk8xj4BytAEtgNK6F42MYSJKHktHHtu48lj4XcEEMieE8PuJ6OZuCYdqw/7R bjxbZp3JgLnJN9O5sAMreEsyAUA4s3jb2IWmQIZguIiI/fR4xSr/Xc0bL9gmUDm/jXdM 1H9whFt8hUQKxvAmU0nVpdGoLhd1IR0HJTgJC3OW6/bLqeZF5AYGv5oh3HBjLN8FP2yQ 0fjsABN7mi3z6UMgtXI3uPOU/1hVjvwJ4aHOMdCxLGaOVUjnOiWj78SwK1OQzdM5dScC RRDQ== X-Gm-Message-State: ACgBeo0+oKt4yueMTXaYjpJbYG06h0FFwMgrKCjkB1+r691r0FZy7Dpn 1aZbWyl0i7XWQZqx7iZhFlRMzosLelj9LUpE X-Received: by 2002:adf:f543:0:b0:228:c692:127a with SMTP id j3-20020adff543000000b00228c692127amr3350438wrp.246.1662453502433; Tue, 06 Sep 2022 01:38:22 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Ilya Leoshkevich Subject: [PULL v3 04/20] linux-user: Honor PT_GNU_STACK Date: Tue, 6 Sep 2022 09:37:59 +0100 Message-Id: <20220906083815.252478-5-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::434; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x434.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" Map the stack executable if required by default or on demand. Acked-by: Ilya Leoshkevich Tested-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- include/elf.h | 1 + linux-user/qemu.h | 1 + linux-user/elfload.c | 19 ++++++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/elf.h b/include/elf.h index 3a4bcb646a..3d6b9062c0 100644 --- a/include/elf.h +++ b/include/elf.h @@ -31,6 +31,7 @@ typedef int64_t Elf64_Sxword; #define PT_LOPROC 0x70000000 #define PT_HIPROC 0x7fffffff +#define PT_GNU_STACK (PT_LOOS + 0x474e551) #define PT_GNU_PROPERTY (PT_LOOS + 0x474e553) #define PT_MIPS_REGINFO 0x70000000 diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 7d90de1b15..e2e93fbd1d 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -48,6 +48,7 @@ struct image_info { uint32_t elf_flags; int personality; abi_ulong alignment; + bool exec_stack; /* Generic semihosting knows about these pointers. */ abi_ulong arg_strings; /* strings for argv */ diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 82fecf9e5a..ba5c4c02e5 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -232,6 +232,7 @@ static bool init_guest_commpage(void) #define ELF_ARCH EM_386 #define ELF_PLATFORM get_elf_platform() +#define EXSTACK_DEFAULT true static const char *get_elf_platform(void) { @@ -308,6 +309,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en #define ELF_ARCH EM_ARM #define ELF_CLASS ELFCLASS32 +#define EXSTACK_DEFAULT true static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop) @@ -776,6 +778,7 @@ static inline void init_thread(struct target_pt_regs *regs, #else #define ELF_CLASS ELFCLASS32 +#define EXSTACK_DEFAULT true #endif @@ -973,6 +976,7 @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUPPCState *en #define ELF_CLASS ELFCLASS64 #define ELF_ARCH EM_LOONGARCH +#define EXSTACK_DEFAULT true #define elf_check_arch(x) ((x) == EM_LOONGARCH) @@ -1068,6 +1072,7 @@ static uint32_t get_elf_hwcap(void) #define ELF_CLASS ELFCLASS32 #endif #define ELF_ARCH EM_MIPS +#define EXSTACK_DEFAULT true #ifdef TARGET_ABI_MIPSN32 #define elf_check_abi(x) ((x) & EF_MIPS_ABI2) @@ -1806,6 +1811,10 @@ static inline void init_thread(struct target_pt_regs *regs, #define bswaptls(ptr) bswap32s(ptr) #endif +#ifndef EXSTACK_DEFAULT +#define EXSTACK_DEFAULT false +#endif + #include "elf.h" /* We must delay the following stanzas until after "elf.h". */ @@ -2081,6 +2090,7 @@ static abi_ulong setup_arg_pages(struct linux_binprm *bprm, struct image_info *info) { abi_ulong size, error, guard; + int prot; size = guest_stack_size; if (size < STACK_LOWER_LIMIT) { @@ -2091,7 +2101,11 @@ static abi_ulong setup_arg_pages(struct linux_binprm *bprm, guard = qemu_real_host_page_size(); } - error = target_mmap(0, size + guard, PROT_READ | PROT_WRITE, + prot = PROT_READ | PROT_WRITE; + if (info->exec_stack) { + prot |= PROT_EXEC; + } + error = target_mmap(0, size + guard, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (error == -1) { perror("mmap stack"); @@ -2921,6 +2935,7 @@ static void load_elf_image(const char *image_name, int image_fd, */ loaddr = -1, hiaddr = 0; info->alignment = 0; + info->exec_stack = EXSTACK_DEFAULT; for (i = 0; i < ehdr->e_phnum; ++i) { struct elf_phdr *eppnt = phdr + i; if (eppnt->p_type == PT_LOAD) { @@ -2963,6 +2978,8 @@ static void load_elf_image(const char *image_name, int image_fd, if (!parse_elf_properties(image_fd, info, eppnt, bprm_buf, &err)) { goto exit_errmsg; } + } else if (eppnt->p_type == PT_GNU_STACK) { + info->exec_stack = eppnt->p_flags & PF_X; } } From patchwork Tue Sep 6 08:38:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602958 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4336919mae; Tue, 6 Sep 2022 01:53:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR4W8X4Hv6KFTbXCo6GrJEYOAtDI/5ar9HaX0XgIvg8CMdwZ5xPvVYCffQ4oFxKp/WpvkzF4 X-Received: by 2002:ad4:5ca2:0:b0:4aa:9d05:2424 with SMTP id q2-20020ad45ca2000000b004aa9d052424mr2999342qvh.71.1662454421646; Tue, 06 Sep 2022 01:53:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662454421; cv=none; d=google.com; s=arc-20160816; b=m3LL3yTFpTkaJwez3hF3F2x/iI3TWN2tZ1VOTuixJek0rnb6TiegDk61tAzqI4zN5P /Gv9QtP7ypvJXEaJVi9KkGbJLa5CzFHpn3sBuwM+hILdv/KkEP9FzmTtmMm8XbYtpAPD kBRHnzwMlmN8EfWRMNfSznbuP4plG+4PuOiyNTfMV6s7yRU/2Y+j+J4w+XMr4IYDUDvx rkclkGF35wdZEsgVvYB0pvV9JLolysT1Wgz5UGMlZqCL0TCuWrK2oT46S6h3xeDJi3N4 L3UrITrsCrGe3wN4ADvr2D5LKY8FxxoFp4sbLBD1uPOOlTcRolJWNM7tnWaIThqH6V2U 3Kbg== 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=SHzx12Rsu42Ye71toTN4bWIrkmgQVEH0DPBud2OqwOk=; b=JQkmBj5Mdtg2D0kEmHxokB2VzKpZrHPZGud7v/3ix8rvD10NE1IT5ugKLVeUcUe2ot QCxq0WMN0BcqUH3hWUNmqLvP8niIN/vjw0W47X+EMh1HzEUqsqLFZN/kz1CDKGZnGyay 0ejK1t1inKpVujUWO5VOqz6W+ftLFKIzDSHJ5wVpvXsKjCCS0cTTcj5nREwECyyFVrGC bqvt6QlYN9EmkGoziiFRU+HR69dHaMQgMOKoIWFDt8So79t+9W0BOq8PxinBMRL0vXfj lC7fwGOcQFwoADANOWuhVElu7fA+JCy8sGVr9r1j6eCtuNCxTTDtVO7htj6veOd5ZMh7 QhGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Csjhu9mo; 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 h12-20020ae9ec0c000000b006b97554a843si6279381qkg.206.2022.09.06.01.53.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 01:53: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=Csjhu9mo; 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]:41560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUKz-0006CU-8n for patch@linaro.org; Tue, 06 Sep 2022 04:53:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6E-0002WP-Vt for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:27 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:36854) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6D-0005UN-5h for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:26 -0400 Received: by mail-wr1-x434.google.com with SMTP id b17so958186wrq.3 for ; Tue, 06 Sep 2022 01:38: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:subject:date; bh=SHzx12Rsu42Ye71toTN4bWIrkmgQVEH0DPBud2OqwOk=; b=Csjhu9mohES5bPcnQJYCGPV8g0GkPzTdyynIr7qrwep92I6pUW50CffLG1AyYzPoTq S4dA6okoYsC8Hl3GjuMu+7ZOSKVUaPorMmLuLmIVtV2SYepQ/4aCs5PX7ZpVfBCbFUzb jkfIZ43TJtZem5G0nLXaW7DdEwtyxlQkNYhz2KWQIpxy5ZIogULnXL82RNZLV5EBCS1U BsAgnWF7i44XSa1kbe3YeCQhhPT6EtGub1pGB7O45JpjYWUlCeco4C8/363G3ILvyS/U DMR7P8C6WXz5U3E8/WaKGHTxWpGEQwRotYDxFxGrR6ZFks7NNlHSn2H4vE3ayw4nO6Uk xHog== 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=SHzx12Rsu42Ye71toTN4bWIrkmgQVEH0DPBud2OqwOk=; b=IuKbMo9ULFAOlbEgKc3v1KbT1kOFqc8LXEF85VLfi9werS7+R7ONDCftAoB9gk0G8r c68OcfYRZtcZO1DTtV1w/wD3Y61r4kGnkWJDPz4I0IZddljYakNbanmgYWqTAKAlzuNb 29sSzlbfY2wyf6hsJlGvqodgS2b3JNP6t5ulHIjYO3Bf/OGpkC3yPAc52V+rsemXnGIK OIUZGd1KF5jPm56czQSRGNnvqGlLmj56vFS/fRGrh0D6vyOFK/7sYPPIFCvKdoq5oF7Z uvT4LNkU04rcavvW17AIPhrTlS43NHpbNc4v3bW4RDm5l+mdFNh97HRSTqKB4Q/t2vgY MXLg== X-Gm-Message-State: ACgBeo0lbZc8s0o8UMmg9V8I82oXth7h5VWK8Bwq+3QBSXzEAgLl6slA B9F225QoED8Hp1EaD398MmsTXeq6agSllLhI X-Received: by 2002:a5d:584f:0:b0:226:edcd:b467 with SMTP id i15-20020a5d584f000000b00226edcdb467mr15281074wrf.363.1662453503360; Tue, 06 Sep 2022 01:38:23 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Ilya Leoshkevich Subject: [PULL v3 05/20] linux-user: Clear translations on mprotect() Date: Tue, 6 Sep 2022 09:38:00 +0100 Message-Id: <20220906083815.252478-6-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::434; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x434.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" From: Ilya Leoshkevich Currently it's possible to execute pages that do not have PAGE_EXEC if there is an existing translation block. Fix by invalidating TBs that touch the affected pages. Signed-off-by: Ilya Leoshkevich Message-Id: <20220817150506.592862-2-iii@linux.ibm.com> Signed-off-by: Richard Henderson --- linux-user/mmap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/linux-user/mmap.c b/linux-user/mmap.c index 048c4135af..6a828e8418 100644 --- a/linux-user/mmap.c +++ b/linux-user/mmap.c @@ -177,9 +177,11 @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) goto error; } } + page_set_flags(start, start + len, page_flags); - mmap_unlock(); - return 0; + tb_invalidate_phys_range(start, start + len); + ret = 0; + error: mmap_unlock(); return ret; From patchwork Tue Sep 6 08:38:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602962 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4340629mae; Tue, 6 Sep 2022 02:00:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR4ZdPJwa+7EPZT2FFZEmx++vlM4CpaZVo9He41MhWnCb1Ho4Bf3nY0n1OuzW9gps2zgHRcs X-Received: by 2002:a05:6214:cc5:b0:49d:af6b:5363 with SMTP id 5-20020a0562140cc500b0049daf6b5363mr11840668qvx.33.1662454853961; Tue, 06 Sep 2022 02:00:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662454853; cv=none; d=google.com; s=arc-20160816; b=yihuIICliQzbJUrZJDRGW/wP0dbpcwttsmw04QywOYM2zw0Ja1LgQSw0N2e9lMQzIf 7W1nRY/L9R7/6lib49hrxgpQuZXV5xID2v2kK3LTSd1DPb3B5Fh53WJQEPWZXE7RmGIQ R6yfGaOfxDV5O82aCGwPSceQ72KQi7dHiJtiG/udRR2R9hG6NLhGWR5c4HieRcXAZuwn ImRf1ous4s6FrRvFsFuF1mpgvPzmN0pAvReqCBk6YstZEnn24Y2JOIUL5St2scvgGxur oi9GrX3olIzL3vdYZhwXKvWJ+WV+9AOsPlRr0tVPK9jrKfF5QmaV49EvSFXjl/mUq+cg ETjA== 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=HHNtzSSJtX30aB1753TWle01U0aOKhRaC897K6yvm6M=; b=UlFX4pU7w5VVGYWa8p9LI6VmZiDZO1Cq8i14JAkC6uzgLZxMGXxyME+fpVOBU61zm8 g1pOZSnYMTZ6xaQYN9hkfqDkMtefHOz2ZJKOF3h4765X0pS5KnpxH/dw/c3wva3WRAjt IISPQPbqIq9onQveTtakQ0oZiUuE76hZG0F9qEt0S0YtxAPQxOpVckgeLCpAtQbaD/eV gWHA8ZoLm2hYBjSs5m6Fi39PK5DaQxq8oqqE2D7TPRkFOcHmvXD/9ckFpFBNSC7Ap7CH mXKiu+/riJXUrbhXEgNaCDdpQVHkkDavW4m4JKcxj/w2mW7X8JjaYhUXCZXVCyQGIMJE FlxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uqxklyQ3; 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 gu15-20020a056214260f00b004a5dee54dbfsi3258281qvb.298.2022.09.06.02.00.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 02:00:53 -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=uqxklyQ3; 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]:58800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVURx-0005Ya-Am for patch@linaro.org; Tue, 06 Sep 2022 05:00:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6F-0002XZ-LR for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:27 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:35580) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6D-0005Ut-T2 for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:27 -0400 Received: by mail-wr1-x435.google.com with SMTP id bz13so10891874wrb.2 for ; Tue, 06 Sep 2022 01:38:25 -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=HHNtzSSJtX30aB1753TWle01U0aOKhRaC897K6yvm6M=; b=uqxklyQ3HFRS2tE0yBJiwzeRelyIrKs2PFTCzDs587hcq3iY55y/ys/Q7uPFfdmbec dalgO+9v6zWt7KppTNwE+NEeDuYxQ134TND2R0MaBDy8tKkhPi3CF5ftlD7OILPtx528 HeKSGZadsBHMnEGOZYJ1EZOEuQUrVT2gt/OCuPAAXtULZMU9WioTFZpGa/U+douqMHfl az+7LB19avx4duWal7nP5Lws3k4mm1h9ivpitVuh+VT2+ryjsG77VacrVhjiZreXTAL6 NAzANRVj+A6L7/YoEzCHv10o8p0XVRZLNNh+fQ4fynCX6WRcg6I4vVY7S1NAyxbQB2z+ kL7Q== 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=HHNtzSSJtX30aB1753TWle01U0aOKhRaC897K6yvm6M=; b=Eere8SuwS/StqR6YVpntF081ou9M/GZ6RBQQ9dGXCsHaY1oO1myFFz5sQKVSkxkux1 38LVEgtk6/lRPQKrlvU0NZ7qX3+5zOtorCNy0mHEI37N6Ruzky+OD5e1Ey2qCpCOg1JM IJXHXUN5NSbTPhjZTy1FQRgabNpJAVYu/FsG13BYdiaPyr1ToEnwSDdEo1bTFKYhXiG9 72td482v4MrMad6EeQH/HQi4nV93BRUFmk6TyckBOTZTzFAeLc30dgBZ/YcFLlkK4z6q ymWNN8rYqoZytIbmb3apLuIpwRCJy2r0mj1wjzs854SzCF26iKXHq95nLQnZwnRfj2D7 7VRw== X-Gm-Message-State: ACgBeo0YJ4t8Z8C6mbWNkgy7172vPRfaiw6325nzjWMAvxkOy7tA1MXy gtWTgoWcuOWGp5sP9oaoKLKRPHPbUfhzsbQv X-Received: by 2002:a5d:6d0b:0:b0:222:955a:8774 with SMTP id e11-20020a5d6d0b000000b00222955a8774mr25341767wrq.129.1662453504432; Tue, 06 Sep 2022 01:38:24 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Ilya Leoshkevich Subject: [PULL v3 06/20] tests/tcg/i386: Move smc_code2 to an executable section Date: Tue, 6 Sep 2022 09:38:01 +0100 Message-Id: <20220906083815.252478-7-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::435; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-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, 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 put this code into a section that is both writable and executable. Note that this test did not run on hardware beforehand either. Acked-by: Ilya Leoshkevich Tested-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- tests/tcg/i386/test-i386.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tcg/i386/test-i386.c b/tests/tcg/i386/test-i386.c index ac8d5a3c1f..e6b308a2c0 100644 --- a/tests/tcg/i386/test-i386.c +++ b/tests/tcg/i386/test-i386.c @@ -1998,7 +1998,7 @@ uint8_t code[] = { 0xc3, /* ret */ }; -asm(".section \".data\"\n" +asm(".section \".data_x\",\"awx\"\n" "smc_code2:\n" "movl 4(%esp), %eax\n" "movl %eax, smc_patch_addr2 + 1\n" From patchwork Tue Sep 6 08:38:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602955 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4333720mae; Tue, 6 Sep 2022 01:47:39 -0700 (PDT) X-Google-Smtp-Source: AA6agR6R22YkhJIc2jqFMCQSBN2Zhk4nDU2y5yFXrC4QNaOkhlOwiNB/49OaYfxO+BeXx4fsvKUb X-Received: by 2002:a05:622a:1209:b0:344:92e0:71c5 with SMTP id y9-20020a05622a120900b0034492e071c5mr41851406qtx.606.1662454059529; Tue, 06 Sep 2022 01:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662454059; cv=none; d=google.com; s=arc-20160816; b=nizOhWnoO2fGW1BN5VN2hcTH2fgaK0V5gg7okGDDbFLqbTbQPIIOzEoDtr8aAFU8Ps OEvCIKd7mzdAgkqsZNti2K33Gt4Tv9bHjIDlAAYTJONorY40goPWKHt7ZGYzxZVjBa8x p3dKCnaLFZoDxxFyg4sVbap29j11ow8uNKR4rjCqpf2ftTjQjvxZuH7ZDw1CzHRqdp34 HFjT01WMffRFliQHVHVV380bRJqppAP5UJeimcb3Q6Y6xzJY26fCqozMKUznh1517XFX oVpb+KF+z4DLTF27h0iRhibqyjS4y1XpT4xNLMl1iodr9X3yTsF6DM+p5+zFIcJGplIg DKUw== 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=OsbFR6exiIugNlN/OA1NiX9KQk6dg8u5+nqhU943Djk=; b=0dZTGBGIjNFXH8B2PMqWtCayXElD/rqAAWkyfcBmhk15TszmeSal7XLBhqWBtQWFRc O0NIGhW8WR2q7hJpH/+82N3GCiU1DYCHF8MDN9exACgSFzS3lElqWEMwFa17AkukBh5g g2HI4NkRoROFvrbuxOr/TsPrxWiL2ZokdwoejeOJ6a0BJu2u+OD+4gwTLYvuyELoXXTk Fk4IvTEqA/NisJVkiGwCxriZI3trTGSaVaFRibFS/NyR/xnEU7UN8xLsP0vG13gat+jt +WqO03jwkpfT+Ir/qLLJGEtCRBjYFDaOdG/AJEffeG/3Tses3jN/IGC6NX25Xow693Jq q/Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cm14Vttj; 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 fn12-20020ad45d6c000000b00498f81c5cdfsi7217968qvb.191.2022.09.06.01.47.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 01:47:39 -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=cm14Vttj; 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]:39232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUF9-0001q1-2U for patch@linaro.org; Tue, 06 Sep 2022 04:47:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6K-0002e1-Gn for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:32 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:34700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6F-0005Vz-2X for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:32 -0400 Received: by mail-wr1-x42f.google.com with SMTP id e13so14320449wrm.1 for ; Tue, 06 Sep 2022 01:38:26 -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=OsbFR6exiIugNlN/OA1NiX9KQk6dg8u5+nqhU943Djk=; b=cm14VttjBwtMEks5SXBiyRbaUIzaOWJS59TfLY/n3NcI8wi2xZWj5ktLutrx21+FNm lKnEAbD4NjpNAV6Wkkd3jV+vMwsJMwaN+9vwzLgbZHiZblz1pmO2mo1yfNRzkNmayKab 9ROP/iV7YHokIyHeaUmcgz8PaRtrufvumOlBauYbS/+qAjTKco/GKnsgz7H3mat6Lu4G yTAQ5/h2ZLPeINQT//L25r5BLY8+t6IyyQ9t4GFf8jndyS8FeqM8C/zQ4QJo1CXz1QQP ZINy7LgVUyQl4nIIRJWi/XThO0KeDK+cWA1y8mC9jf7cvurt+pZ1Nze9DzeCnZCwo3eo ahQg== 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=OsbFR6exiIugNlN/OA1NiX9KQk6dg8u5+nqhU943Djk=; b=IYpfjvyF/WCxZub/DpCX5jyL+kNfVJHJqxWu+xbzliMjRkuSG+3fpdG44ayIgAdbW2 1cZPmo/wegYZNfDMC024O/gADRpnFUWep3k7rvRZ/1BFORdvasPQQbJnAusSI98u1aTr h+xQCdWzkBDbtVagNSzDNyQPvaeYxFa846Li/DyxfXw2eujfpw5EtBrOw/muNCPlPwDK 973w4gAb9+nYBaQ2Xh3M4BaeKMv6g8WhhjFo0A7veZ7bSDNwcAdZjilcE7l+YR6Kn/gp K+pPhNXvc63949J0fqvSxnfm/I6ktxIiKl85u8iQDAchPtrzF914MxoQbliYIT7SNTDx Sskw== X-Gm-Message-State: ACgBeo1wDoHjgCTaaM2Q5WoyjcQ6BHZtyn3KJK2yJ/t9KlJpoZhAlqYs SIqJIJSItN3uthv0lI0/QDgufab2dW5dMv4/ X-Received: by 2002:a5d:64e5:0:b0:220:7859:7bc with SMTP id g5-20020a5d64e5000000b00220785907bcmr25102380wri.669.1662453505693; Tue, 06 Sep 2022 01:38:25 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Ilya Leoshkevich , Alistair Francis Subject: [PULL v3 07/20] accel/tcg: Introduce is_same_page() Date: Tue, 6 Sep 2022 09:38:02 +0100 Message-Id: <20220906083815.252478-8-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::42f; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42f.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" From: Ilya Leoshkevich Introduce a function that checks whether a given address is on the same page as where disassembly started. Having it improves readability of the following patches. Reviewed-by: Alistair Francis Signed-off-by: Ilya Leoshkevich Message-Id: <20220811095534.241224-3-iii@linux.ibm.com> Reviewed-by: Richard Henderson [rth: Make the DisasContextBase parameter const.] Signed-off-by: Richard Henderson --- include/exec/translator.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/exec/translator.h b/include/exec/translator.h index 7db6845535..0d0bf3a31e 100644 --- a/include/exec/translator.h +++ b/include/exec/translator.h @@ -187,4 +187,14 @@ FOR_EACH_TRANSLATOR_LD(GEN_TRANSLATOR_LD) #undef GEN_TRANSLATOR_LD +/* + * Return whether addr is on the same page as where disassembly started. + * Translators can use this to enforce the rule that only single-insn + * translation blocks are allowed to cross page boundaries. + */ +static inline bool is_same_page(const DisasContextBase *db, target_ulong addr) +{ + return ((addr ^ db->pc_first) & TARGET_PAGE_MASK) == 0; +} + #endif /* EXEC__TRANSLATOR_H */ From patchwork Tue Sep 6 08:38:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602951 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4330305mae; Tue, 6 Sep 2022 01:41:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR7tupeMBcM1D9HgcF2KF6/weMhxHS/AegpqMXTtwmESiKHy5G3eLwWRwP8i/eWwiUbhW3WW X-Received: by 2002:a05:6214:2625:b0:4a6:ca62:ed1d with SMTP id gv5-20020a056214262500b004a6ca62ed1dmr6796301qvb.126.1662453682242; Tue, 06 Sep 2022 01:41:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662453682; cv=none; d=google.com; s=arc-20160816; b=xBSDvKJB/gu/6h7PjUZHaI92raaAPtdHlROvYzVb9+ZNhsT31lwE3mU2Mcv6NgodQ6 ewocfjJtuCJMb89g+APlt1ezyGo5QuRWZPPnPXUL9BkYDoejQZhq/mrw3eVyFc59tKHm u5XNdfRA9twWVDS116XezLBHIU5qEVPJrDfJRNDmBLGkKMtRVWwjBp/DJcbloSV0kf/b 9otlF6TDKaxTa8HwFxx4RbabSNStKxeI5Qu7h9r7DdfhaXrwHRc3IR1pDYtsK5tUDTT0 ECu3/f06STVOu5RRJv+b1VDMxhqApcbtgXF8rK0vQG9PrgZA8hewZrTGOSCNQ+fRxNEi CC3Q== 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=M8k7INWbeFTVJiul2ENAwHhs/2Kfd59wQP99Hj3ZwhA=; b=yPQ4inuKam37TnP4Eka0MaIb/RNoNu+n5fLOBdvaSm0zZyIJ8Zh3ojRQbGCxvbtbpW a+W0HMXMkCnTeXFD+uE6Dh/K2+KZdH9C2ZSGiMYIulUjZNrbMlEh+btCwvgbzdIeXCKH Ry/PsLD+2d9aCNZZnK7UeGpK1i738RXWJcJTIz1hy4nmmSbwJcORG++QboV0VqmqmVan JLz5M5ibKQNK1Sj88yIA+jfuUb+3L0f9eQ978kxorNW+kLoWtc1guAl0s3rDhNNBZi84 l7SXG3qCKXz71BEUZq2yViZ/3Da1NUo9QGWCZ1N7BuQzMoD+51m0+dK3JkVYXRfyujAm XKNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uVh7joT1; 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 d69-20020ae9ef48000000b006bac0260dabsi6271371qkg.534.2022.09.06.01.41.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 01:41: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=uVh7joT1; 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]:38190 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVU93-0002gY-Mv for patch@linaro.org; Tue, 06 Sep 2022 04:41:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6I-0002cw-Hx for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:31 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:46643) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6G-0005WW-Bq for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:30 -0400 Received: by mail-wr1-x429.google.com with SMTP id e20so14271247wri.13 for ; Tue, 06 Sep 2022 01:38:27 -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=M8k7INWbeFTVJiul2ENAwHhs/2Kfd59wQP99Hj3ZwhA=; b=uVh7joT1ksZzB5iRXfj5wyC0Qq20I2Z81gM+YPauWxcLRR3M3SeFz1RZSLQ6UQip0p gashSQKN+gE0aUuAbasweKwtd2MqeTn1eRZZuKJ+bBbxM5SIkjNkDOcv8CInKCF7S7Hx xHy6Uz7FKKepnPvZsktrdl2UwTSqymCkrB90A6XOaxfBgv4WYatp1rtqxiL/pFBMydjz huZ1fs+Lkumo98Y+AmSWT/hgsMSIXk5a1ltitXTC5QrDTNF8X7/jBFKO0QGOaegcbkbz 7INNWY7m3BspOKTijlgNP3NfN6RVXJ21fHiLA/sYewlSAGK8uX6Rxlb1wZWSO3m7K8sE ERjw== 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=M8k7INWbeFTVJiul2ENAwHhs/2Kfd59wQP99Hj3ZwhA=; b=n7ZgcitNuz6mQybaU/KgtN1Jk1XpdJqNANKIQivnxS4S7LoMIGZk5Vrw/bmZ0S3//f yPhnMS0TmoWIyS7Cn07delwy1UczLCzlrc2f3fh0PnBHuyvcnNc6ruw42ayfwl5qRH56 qSP4SkbnOuynIkrX26qm+42UGHuSrtcd14kqF1turI9pFnZrDvLnPWiCBsi80ZSf4jST jPe8jlRFBtrJJQKHmKtQ1Dk1Ii4ZLjY8Epex0Vs9Ng7HZSjkFq7QNU9JCpeH+thmjKxz LnYFjExA7AF+zhs7FsuJU8NdZW8w8l9OmYRY+LI/P/NUaUc3K7Vf7zTFCZGlFMwpCLUA Ey4Q== X-Gm-Message-State: ACgBeo3sW4NS9ZrX82RlaqLOYg5DlyrHHkGk/2pN9Y7tPPEXX7fX652A WBjcZaN4bPYNogG/q1vnOfGJQqIGMkiVuJ5D X-Received: by 2002:a5d:4405:0:b0:228:dab2:d900 with SMTP id z5-20020a5d4405000000b00228dab2d900mr769031wrq.502.1662453506955; Tue, 06 Sep 2022 01:38:26 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Ilya Leoshkevich , Alistair Francis Subject: [PULL v3 08/20] accel/tcg: Properly implement get_page_addr_code for user-only Date: Tue, 6 Sep 2022 09:38:03 +0100 Message-Id: <20220906083815.252478-9-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::429; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x429.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" The current implementation is a no-op, simply returning addr. This is incorrect, because we ought to be checking the page permissions for execution. Make get_page_addr_code inline for both implementations. Acked-by: Ilya Leoshkevich Tested-by: Ilya Leoshkevich Acked-by: Alistair Francis Signed-off-by: Richard Henderson --- include/exec/exec-all.h | 85 ++++++++++++++--------------------------- accel/tcg/cputlb.c | 5 --- accel/tcg/user-exec.c | 14 +++++++ 3 files changed, 42 insertions(+), 62 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 311e5fb422..0475ec6007 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -598,43 +598,44 @@ struct MemoryRegionSection *iotlb_to_section(CPUState *cpu, hwaddr index, MemTxAttrs attrs); #endif -#if defined(CONFIG_USER_ONLY) -void mmap_lock(void); -void mmap_unlock(void); -bool have_mmap_lock(void); - /** - * get_page_addr_code() - user-mode version + * get_page_addr_code_hostp() * @env: CPUArchState * @addr: guest virtual address of guest code * - * Returns @addr. + * See get_page_addr_code() (full-system version) for documentation on the + * return value. + * + * Sets *@hostp (when @hostp is non-NULL) as follows. + * If the return value is -1, sets *@hostp to NULL. Otherwise, sets *@hostp + * to the host address where @addr's content is kept. + * + * Note: this function can trigger an exception. + */ +tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, + void **hostp); + +/** + * get_page_addr_code() + * @env: CPUArchState + * @addr: guest virtual address of guest code + * + * If we cannot translate and execute from the entire RAM page, or if + * the region is not backed by RAM, returns -1. Otherwise, returns the + * ram_addr_t corresponding to the guest code at @addr. + * + * Note: this function can trigger an exception. */ static inline tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr) { - return addr; + return get_page_addr_code_hostp(env, addr, NULL); } -/** - * get_page_addr_code_hostp() - user-mode version - * @env: CPUArchState - * @addr: guest virtual address of guest code - * - * Returns @addr. - * - * If @hostp is non-NULL, sets *@hostp to the host address where @addr's content - * is kept. - */ -static inline tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, - target_ulong addr, - void **hostp) -{ - if (hostp) { - *hostp = g2h_untagged(addr); - } - return addr; -} +#if defined(CONFIG_USER_ONLY) +void mmap_lock(void); +void mmap_unlock(void); +bool have_mmap_lock(void); /** * adjust_signal_pc: @@ -691,36 +692,6 @@ G_NORETURN void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr, static inline void mmap_lock(void) {} static inline void mmap_unlock(void) {} -/** - * get_page_addr_code() - full-system version - * @env: CPUArchState - * @addr: guest virtual address of guest code - * - * If we cannot translate and execute from the entire RAM page, or if - * the region is not backed by RAM, returns -1. Otherwise, returns the - * ram_addr_t corresponding to the guest code at @addr. - * - * Note: this function can trigger an exception. - */ -tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr); - -/** - * get_page_addr_code_hostp() - full-system version - * @env: CPUArchState - * @addr: guest virtual address of guest code - * - * See get_page_addr_code() (full-system version) for documentation on the - * return value. - * - * Sets *@hostp (when @hostp is non-NULL) as follows. - * If the return value is -1, sets *@hostp to NULL. Otherwise, sets *@hostp - * to the host address where @addr's content is kept. - * - * Note: this function can trigger an exception. - */ -tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, - void **hostp); - void tlb_reset_dirty(CPUState *cpu, ram_addr_t start1, ram_addr_t length); void tlb_set_dirty(CPUState *cpu, target_ulong vaddr); diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index a46f3a654d..43bd65c973 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1544,11 +1544,6 @@ tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, return qemu_ram_addr_from_host_nofail(p); } -tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr) -{ - return get_page_addr_code_hostp(env, addr, NULL); -} - static void notdirty_write(CPUState *cpu, vaddr mem_vaddr, unsigned size, CPUIOTLBEntry *iotlbentry, uintptr_t retaddr) { diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 20ada5472b..2bc4394b80 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -199,6 +199,20 @@ void *probe_access(CPUArchState *env, target_ulong addr, int size, return size ? g2h(env_cpu(env), addr) : NULL; } +tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, + void **hostp) +{ + int flags; + + flags = probe_access_internal(env, addr, 1, MMU_INST_FETCH, false, 0); + g_assert(flags == 0); + + if (hostp) { + *hostp = g2h_untagged(addr); + } + return addr; +} + /* The softmmu versions of these helpers are in cputlb.c. */ /* From patchwork Tue Sep 6 08:38:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602954 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4332750mae; Tue, 6 Sep 2022 01:45:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR5HgrIANxfpYVtM0vKpEIKNAAfDz6ipvNRkAxpGOTtSL71ZkRjQ7kvzmyvkreL4S3HNnSXr X-Received: by 2002:a05:620a:2723:b0:6bc:5cdc:88f2 with SMTP id b35-20020a05620a272300b006bc5cdc88f2mr35405057qkp.607.1662453956987; Tue, 06 Sep 2022 01:45:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662453956; cv=none; d=google.com; s=arc-20160816; b=exHj6+0WzvQe0IYJk3kc5v1iH9KQ8y+Css7xZgj/3sdj85Bpo+Ss5bq+bARJcxwWPb GUMscgsv8PzHRTR4wfO79mmLc9ClnZ8I4QX+B4ZpIN2tB46Q501UQ8Nq+LmtVUciey5D +ItWMQso/IgNXttuRz2cWqnRT/qzQBZ1BpysBo289s8VL/JZkFreqXmXaJGFOxy+Di60 2vkCxw+NAm5uF9a/mijMaVIAr7pULMPGR0jwf5Wi4xdDpcQstf0lqfeAWWZl1S7FPBIm LMrYXSr3f9GybEFhZSWuDXuvp57E9L9BZqbn+swWfdDsZ71Jy65rjX39hVdU677uqux9 fGTw== 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=gUYWndQQ8pFmIauaAuMmFCedmEzSZQGaU3WPNExELkk=; b=zlmsWU6N6dRI+TN72bizOkWAOkRDiUKJ6jgP3cOmMM/JNp5t3u5D5b44U3dYwnznEX /YmEh3zEjzz5C3buOdHBQHbqMy7qx9vbb0t427uVb1yErw2Cbx0HDSuuXN/rwsZVthUV vrazksRKLzeDLhQFq3bvljlT9aDdNWvWgka9EY6aUmU6EqSSG1lBqCW1EA+14/YVdcwW t+0CVIMsxkKFskX+szyN/SAp6kaWfXTHnIx8Po0w492CauZoRzjcHYUshrXjxLlRmsYi NnL5GnIN9pTWvjao+PmAiSj5b4m+5ekkiPHotr5YEapU7S6m4ZGO6+e/RsqHm4Qh4Eei /2Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YJPu8vRI; 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 dw12-20020a0562140a0c00b004aa9f544bbesi633506qvb.390.2022.09.06.01.45.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 01:45:56 -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=YJPu8vRI; 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]:60336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUDU-0000Jh-Ip for patch@linaro.org; Tue, 06 Sep 2022 04:45:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6J-0002dj-CH for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:32 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:44633) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6H-0005Wi-L5 for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:31 -0400 Received: by mail-wr1-x430.google.com with SMTP id c11so10072558wrp.11 for ; Tue, 06 Sep 2022 01:38:29 -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=gUYWndQQ8pFmIauaAuMmFCedmEzSZQGaU3WPNExELkk=; b=YJPu8vRIR0CWOlnSgM+bi0cJkHIVqU/wq6eKGRxpO1++OUlBU53FkX7k9pLMY1Nv8y HxoJ4oAwBDOBMWjTo/V9dqkhgtW5iD8hw2J7ptP/y2X4Owuza43COFzaR/EUF8QyfusO VoVREo0XAi9vnszFzO4fKiCxnT4K8zBWrfF4N7RXxn2KYeiJc+4adGowFdwl6ph2CMlk WMyNkFeHS9zUKXoNwDj0Tj7thdV4MWYBkCXMUZnDmdFCx5SY6n72eQl8rWNO7KLqrdH8 /F7uQYMrgZjbLAmn84BjenjjCNJZcTxg941S4D/Qcp5MqFKXp2cQoFzNyRehqqHsULGK eXZg== 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=gUYWndQQ8pFmIauaAuMmFCedmEzSZQGaU3WPNExELkk=; b=IsgWe2VBN9UZgJyKs87Zq9+uGmYxgA7RBzwZm41Gxws7S/fyKcenURMBzvBy6+nSPg 52sWeXp8JxnoIFmvVrDucagln9CQnz/TACLk4bcUHzoaiLAr2SLYu4cvH0H/o/x0pccv OkT77RuIrkl8dCmEUnDx8QhTmsbTRxugendtl+SoIT64afWlEtopRg5g7s2OL2f8sl9l Jh84Jp0n3ahSRAl4HwAiqhMlyUmzci4y14Wm+tOn5TlZTQr+3lDBfD5YpCe1iFc9twR+ HxUUV3oA11DkRSf1wPnwUFKXKIRCz7AzUD5EJawDqZ8bNjU0xJtVc7118nYSdluyt2pJ 1vqA== X-Gm-Message-State: ACgBeo1yzx40abAqndu/2ie1w5Cn5Jc1P5O0ubeCeNoyUgT6axLWaHLK HqNvvbjeTQ8Z1et0pb+WyNzaxxqDQzH4Ovp9 X-Received: by 2002:a05:6000:144a:b0:220:7181:9283 with SMTP id v10-20020a056000144a00b0022071819283mr25380932wrx.158.1662453508345; Tue, 06 Sep 2022 01:38:28 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Alistair Francis , Ilya Leoshkevich Subject: [PULL v3 09/20] accel/tcg: Unlock mmap_lock after longjmp Date: Tue, 6 Sep 2022 09:38:04 +0100 Message-Id: <20220906083815.252478-10-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::430; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x430.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" The mmap_lock is held around tb_gen_code. While the comment is correct that the lock is dropped when tb_gen_code runs out of memory, the lock is *not* dropped when an exception is raised reading code for translation. Acked-by: Alistair Francis Acked-by: Ilya Leoshkevich Tested-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- accel/tcg/cpu-exec.c | 12 ++++++------ accel/tcg/user-exec.c | 3 --- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index a565a3f8ec..d18081ca6f 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -462,13 +462,11 @@ void cpu_exec_step_atomic(CPUState *cpu) cpu_tb_exec(cpu, tb, &tb_exit); cpu_exec_exit(cpu); } else { - /* - * The mmap_lock is dropped by tb_gen_code if it runs out of - * memory. - */ #ifndef CONFIG_SOFTMMU clear_helper_retaddr(); - tcg_debug_assert(!have_mmap_lock()); + if (have_mmap_lock()) { + mmap_unlock(); + } #endif if (qemu_mutex_iothread_locked()) { qemu_mutex_unlock_iothread(); @@ -936,7 +934,9 @@ int cpu_exec(CPUState *cpu) #ifndef CONFIG_SOFTMMU clear_helper_retaddr(); - tcg_debug_assert(!have_mmap_lock()); + if (have_mmap_lock()) { + mmap_unlock(); + } #endif if (qemu_mutex_iothread_locked()) { qemu_mutex_unlock_iothread(); diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c index 2bc4394b80..521aa8b61e 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -80,10 +80,7 @@ MMUAccessType adjust_signal_pc(uintptr_t *pc, bool is_write) * (and if the translator doesn't handle page boundaries correctly * there's little we can do about that here). Therefore, do not * trigger the unwinder. - * - * Like tb_gen_code, release the memory lock before cpu_loop_exit. */ - mmap_unlock(); *pc = 0; return MMU_INST_FETCH; } From patchwork Tue Sep 6 08:38:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602959 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4337489mae; Tue, 6 Sep 2022 01:54:55 -0700 (PDT) X-Google-Smtp-Source: AA6agR6qKSqYPjMZ1pwm3OSKbPEr2t7aUk7zZC9n1aaYb99CS+w4sHLxfSGyBt0xdLOVRkgkdTLF X-Received: by 2002:a05:622a:110e:b0:343:6f02:99fd with SMTP id e14-20020a05622a110e00b003436f0299fdmr42934903qty.141.1662454495007; Tue, 06 Sep 2022 01:54:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662454495; cv=none; d=google.com; s=arc-20160816; b=E7peYP5z7SBe0fTD9BGbKsx4gMdj11DZywWMJ2iY/Yss79o/Lmfq628jQW76kKDdxx oy8a6BKlC9V8/iRjOw72eA4ry8EAuS/lmSQMP005x4jipq31dlK/4biC0forVFqO4ISa ZF7KaC0kFXb+K6yhBAxTWkIR0ldYC/XceDXpeTURWd3MmQ9b9xrC0rdHarkzbDrgegBH kFtjVKin2Zo5/HPQ5+yRmeE0he1dvClBBY7DZC1sjbul3MbeRL+jJ0/1+ysplD+p36De XYm0VC7SrhQFfxdpapoXbMmRUmAhdNmzQ2/dHeF8BJ8R06qWG7yZnEiklBfmpHDAN69F wxCQ== 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=zG39VovyIZ/PsCMFUhH4j2iQCKj21MZ5YeRW0rCmN4k=; b=VqyOBP6mJu5JI+ozSHyhqdnYZOgO4hKEc/afcRc/p7VpBYwKP5eo2meLrEH3DBwGUd 90vAl7VWpPNObMxUnyjSMpamvlOpQ0vQJ1Y1YXLp1IJayrRCp9NjYbzEHi/+BDdx74kL uuJve/EDnpxGwEzOiE3swfEk0w19Yrri/qZ6sZs+jULI+DqTjhMDhJnEoQ+G22VQLcGF A6PyWQkZTaMyEPRLrvQTqfpJYHOH0o1LLm1a56pjCHoxFGPx7/I9TP2nYXdUkz/bO7az Q/PmyIjd1BL4G2uIruvkB5AKE8rRKPVzyOXpWeGs8lzil+I924utL0e8ENV0vhwGqK0l 1FBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nF7WSL+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 u125-20020ae9d883000000b006bb1387fdc9si5980968qkf.468.2022.09.06.01.54.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 01:54: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=nF7WSL+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]:36070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUMA-00088A-IN for patch@linaro.org; Tue, 06 Sep 2022 04:54:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57622) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6L-0002er-7V for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:33 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:40910) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6J-0005Wy-3m for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:32 -0400 Received: by mail-wm1-x334.google.com with SMTP id h204-20020a1c21d5000000b003a5b467c3abso9111751wmh.5 for ; Tue, 06 Sep 2022 01:38:30 -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=zG39VovyIZ/PsCMFUhH4j2iQCKj21MZ5YeRW0rCmN4k=; b=nF7WSL+BqHfsgJPyQx+cpUVczWpT068d3Bt8wdW/75IYYvhomFLrlqnjXXxwlfwk5N p5caQr2Yk3MCxramc3f2uEDs+UgapmS9DIJ4t1RV0eGPnAs3GFPfFmpYGtwUJGDUE2f/ b4vxHoEmnkRIlwyru3k1qEq4en76Q0FpW0qNntmujEggTJS525ZBjiJIBuhbrqHHa7g6 EhjkqmDrPrIPwQg/4HzVEHHoJDdcZ8aS3T911+CinxVHfxo72KwzyJEPssRV3GMlSrTq KkX4KzT+drYaq0XS2c4av+bzfchHCHga+tWP73cMyRczIFsN+xQVYNafswVqbDUz4+P1 8hEw== 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=zG39VovyIZ/PsCMFUhH4j2iQCKj21MZ5YeRW0rCmN4k=; b=qpGHwz3szH4HqgwQatsq2MhbcRTjFrKeiYgJRE5NSksWllYLBpg0W+64spTcUEQEEv QT7bbwu+I+KPJXWJ65PM2+erIfT34HosYNWWRFf5UIcvKN5QbjUocCnhBPcCZd440qDw kxuMEeQvem6psqWNtmxcZyPsSu+ZdObIcguR6yyQXbUKzN0TM8zZiq3+iwV/wspheBl7 9Kcp5sSFipz/amazlk0ClY7GD36nr3r+wPfx2cBeUGAQPVA0waaRgRTNEjcVkIiYI3Mj koEZ4OWlEhxLLokrFPerr3iKEz3/CrZlIwh8btBUTxmo/dW+fnIkhUEvWeYpvKR5bxqG wPkA== X-Gm-Message-State: ACgBeo3Fpsy8lmkZuGUOPO6HkaJlfqveooAZGcK+Ksxc0wiYx8TRNGbk TlXW8ZsrPw5goANXs31gX+nPMQjksE23yT2h X-Received: by 2002:a05:600c:1c16:b0:3a6:b11:79be with SMTP id j22-20020a05600c1c1600b003a60b1179bemr12638932wms.203.1662453509525; Tue, 06 Sep 2022 01:38:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Alistair Francis , Ilya Leoshkevich Subject: [PULL v3 10/20] accel/tcg: Make tb_htable_lookup static Date: Tue, 6 Sep 2022 09:38:05 +0100 Message-Id: <20220906083815.252478-11-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::334; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x334.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" The function is not used outside of cpu-exec.c. Move it and its subroutines up in the file, before the first use. Reviewed-by: Alistair Francis Acked-by: Ilya Leoshkevich Tested-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- include/exec/exec-all.h | 3 - accel/tcg/cpu-exec.c | 122 ++++++++++++++++++++-------------------- 2 files changed, 61 insertions(+), 64 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 0475ec6007..9f35e3b7a9 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -552,9 +552,6 @@ void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs); #endif void tb_flush(CPUState *cpu); void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr); -TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc, - target_ulong cs_base, uint32_t flags, - uint32_t cflags); void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr); /* GETPC is the true target of the return instruction that we'll execute. */ diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index d18081ca6f..7887af6f45 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -170,6 +170,67 @@ uint32_t curr_cflags(CPUState *cpu) return cflags; } +struct tb_desc { + target_ulong pc; + target_ulong cs_base; + CPUArchState *env; + tb_page_addr_t phys_page1; + uint32_t flags; + uint32_t cflags; + uint32_t trace_vcpu_dstate; +}; + +static bool tb_lookup_cmp(const void *p, const void *d) +{ + const TranslationBlock *tb = p; + const struct tb_desc *desc = d; + + if (tb->pc == desc->pc && + tb->page_addr[0] == desc->phys_page1 && + tb->cs_base == desc->cs_base && + tb->flags == desc->flags && + tb->trace_vcpu_dstate == desc->trace_vcpu_dstate && + tb_cflags(tb) == desc->cflags) { + /* check next page if needed */ + if (tb->page_addr[1] == -1) { + return true; + } else { + tb_page_addr_t phys_page2; + target_ulong virt_page2; + + virt_page2 = (desc->pc & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; + phys_page2 = get_page_addr_code(desc->env, virt_page2); + if (tb->page_addr[1] == phys_page2) { + return true; + } + } + } + return false; +} + +static TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc, + target_ulong cs_base, uint32_t flags, + uint32_t cflags) +{ + tb_page_addr_t phys_pc; + struct tb_desc desc; + uint32_t h; + + desc.env = cpu->env_ptr; + desc.cs_base = cs_base; + desc.flags = flags; + desc.cflags = cflags; + desc.trace_vcpu_dstate = *cpu->trace_dstate; + desc.pc = pc; + phys_pc = get_page_addr_code(desc.env, pc); + if (phys_pc == -1) { + return NULL; + } + desc.phys_page1 = phys_pc & TARGET_PAGE_MASK; + h = tb_hash_func(phys_pc, pc, flags, cflags, *cpu->trace_dstate); + return qht_lookup_custom(&tb_ctx.htable, &desc, h, tb_lookup_cmp); +} + /* Might cause an exception, so have a longjmp destination ready */ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc, target_ulong cs_base, @@ -485,67 +546,6 @@ void cpu_exec_step_atomic(CPUState *cpu) end_exclusive(); } -struct tb_desc { - target_ulong pc; - target_ulong cs_base; - CPUArchState *env; - tb_page_addr_t phys_page1; - uint32_t flags; - uint32_t cflags; - uint32_t trace_vcpu_dstate; -}; - -static bool tb_lookup_cmp(const void *p, const void *d) -{ - const TranslationBlock *tb = p; - const struct tb_desc *desc = d; - - if (tb->pc == desc->pc && - tb->page_addr[0] == desc->phys_page1 && - tb->cs_base == desc->cs_base && - tb->flags == desc->flags && - tb->trace_vcpu_dstate == desc->trace_vcpu_dstate && - tb_cflags(tb) == desc->cflags) { - /* check next page if needed */ - if (tb->page_addr[1] == -1) { - return true; - } else { - tb_page_addr_t phys_page2; - target_ulong virt_page2; - - virt_page2 = (desc->pc & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; - phys_page2 = get_page_addr_code(desc->env, virt_page2); - if (tb->page_addr[1] == phys_page2) { - return true; - } - } - } - return false; -} - -TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc, - target_ulong cs_base, uint32_t flags, - uint32_t cflags) -{ - tb_page_addr_t phys_pc; - struct tb_desc desc; - uint32_t h; - - desc.env = cpu->env_ptr; - desc.cs_base = cs_base; - desc.flags = flags; - desc.cflags = cflags; - desc.trace_vcpu_dstate = *cpu->trace_dstate; - desc.pc = pc; - phys_pc = get_page_addr_code(desc.env, pc); - if (phys_pc == -1) { - return NULL; - } - desc.phys_page1 = phys_pc & TARGET_PAGE_MASK; - h = tb_hash_func(phys_pc, pc, flags, cflags, *cpu->trace_dstate); - return qht_lookup_custom(&tb_ctx.htable, &desc, h, tb_lookup_cmp); -} - void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr) { if (TCG_TARGET_HAS_direct_jump) { From patchwork Tue Sep 6 08:38:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602957 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4336916mae; Tue, 6 Sep 2022 01:53:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR7q8kex0joWwG7RAo9sESXqe4sRcHx9UbD5RfOGZqBcvMqky18/4wUd0hLx/lvOgx2SYVvS X-Received: by 2002:ac8:7d44:0:b0:344:57c4:5f54 with SMTP id h4-20020ac87d44000000b0034457c45f54mr41354280qtb.446.1662454421182; Tue, 06 Sep 2022 01:53:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662454421; cv=none; d=google.com; s=arc-20160816; b=nzBffsntgN6xQeJ8t5slBvOZfa2MP5s2rBYJmFYNkSo9+z5eb2tDSw2SH0xkOC7GJC qJXnsoZS9XE1lTbMF6GE/OcoGz4U4xsCDXrj8yqbLp+mAbAmq45MJt+9UcVyrI2OjaGl MXl/jiZcYt9APXbz7ONwnAgRwaLgl1PsRBLGeOSVcXGnSuzj3MDt9HKGsAmQLCToDeA1 Ikw4VIHHZP/khehtPbrI/IPMZ0Yqo2UV5e9OBFgE+8xxZ+lNzHNO77d4BNve1mRKHPl/ cD3wEIyaPjDFLJNzjMVRsyZ79YPNJ9pz7q7nLB6K6NzIPBoSSTJaa1QXdWEG8P1Pwzoe EfMQ== 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=Kh1uN4/0ovlH8dCidDvOH33OgIiJlJt8Oo88s09rMG4=; b=tT4EbRP0589e0C/yMxPP2siyeb10BLmcnC+i38lNQed4YdTCyfQhdnoKwli7wldrLR owUjmsXWFC5tsVUvx8epLwGciohT0Kvi6kj+KCOwc0Lz2uHvZ1z0kWaGsjAPMTW+8Ilp OgZaTCkpkJ7Fq8OeWY0AimMQrbP76/U2Q2gR2iMSgj/E6ke2JmEpB2nLxOrZcXIP7Avz a5Q2GkNf6sruM9yfQs7p1ZxblBTvvb+d2yhP5N7Hwy/I0qHJV57n5OGfMTfFfI0EgAe3 Mi+/Aeppnm0OXRzCCdUIqQKfgbnHD3xMrBBZezOGbP9fZZRTKHvIkEt0fMxRBd7oahM8 nhxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j2BVEm2T; 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 ew8-20020a05622a514800b0034455769c4csi7134683qtb.523.2022.09.06.01.53.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 01:53: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=j2BVEm2T; 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]:41562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUKw-0006Gp-UM for patch@linaro.org; Tue, 06 Sep 2022 04:53:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6M-0002gC-5f for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:34 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:44631) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6K-0005XD-9j for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:33 -0400 Received: by mail-wr1-x42d.google.com with SMTP id c11so10072719wrp.11 for ; Tue, 06 Sep 2022 01:38:31 -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=Kh1uN4/0ovlH8dCidDvOH33OgIiJlJt8Oo88s09rMG4=; b=j2BVEm2TMcSMYzijCKpwyrlV5lYATrOr3MdPCfi6Dj3B7e+kK3stHxheOP8/Nkd2ne E9kiPmmKJdKePAbeR6C+/UKXXOlWVm9LV3r+IRT+nhJ7KgPFQpNbYioBCemLjpDZufZv yce3wU2lZ4o0K4m2d7IjEQIhI9Da4P42TlKvxdVKF6uMADhZT1OlbbUgS+GFWUd5f6gw 5bSNWjArvp8l/CGUvXHw+L81/zl2cI5ex16pad0fzbjFGdxO0aWKLwW8iWuL91WrX5HZ qSRJiyKGt+E0UiafblXtkvPA4QIUH1DhsZgTiDWk+DRU3jVBFbNA98AULJUMGbu02VOb f7cw== 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=Kh1uN4/0ovlH8dCidDvOH33OgIiJlJt8Oo88s09rMG4=; b=QdMqyi3S6+BayudTn4jnVtQfrBjN6XCd9Vvlz2MvfnPE2/MRU1zzdE/VBPXvnQwtsu 4JtyrfiNz78J9SZZaW2DjO/bj7Kh7+tqmjL+SMX/uFNzxT3EDe25p5ObUm4ugC09CKUc dMYKt1YbW9lzTkACrQl9uooe0zYFSEqmtk8xBZ0cTVv9TarcxkDZd587AjJpvuMoL6tg GqqwmX2NkJ7df1vlFy+9IN/UjKCB3fLa4MUtO0wnTG+9hqWodJhu/37XFJK5rPeo9IPb hvOl3pjwB/H4CgfWq2XitD8Bsd+f4dRZborFL8EcmBFXhrKEkyeKiTPweQC9XI8p1CUl +YDw== X-Gm-Message-State: ACgBeo3kDulzWoXFXzVuzXLl83s/tJ8aq1grKSejhhTy40DnBUz2f7So 9I4vVNWLjqgox/MZyYaRBXLO6veI1cHx5xm5 X-Received: by 2002:a5d:6443:0:b0:228:da41:8274 with SMTP id d3-20020a5d6443000000b00228da418274mr908150wrw.160.1662453510846; Tue, 06 Sep 2022 01:38:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Alistair Francis , Ilya Leoshkevich Subject: [PULL v3 11/20] accel/tcg: Move qemu_ram_addr_from_host_nofail to physmem.c Date: Tue, 6 Sep 2022 09:38:06 +0100 Message-Id: <20220906083815.252478-12-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::42d; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42d.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" The base qemu_ram_addr_from_host function is already in softmmu/physmem.c; move the nofail version to be adjacent. Reviewed-by: Alistair Francis Acked-by: Ilya Leoshkevich Tested-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- include/exec/cpu-common.h | 1 + accel/tcg/cputlb.c | 12 ------------ softmmu/physmem.c | 12 ++++++++++++ 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 2281be4e10..d909429427 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -72,6 +72,7 @@ typedef uintptr_t ram_addr_t; void qemu_ram_remap(ram_addr_t addr, ram_addr_t length); /* This should not be used by devices. */ ram_addr_t qemu_ram_addr_from_host(void *ptr); +ram_addr_t qemu_ram_addr_from_host_nofail(void *ptr); RAMBlock *qemu_ram_block_by_name(const char *name); RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset, ram_addr_t *offset); diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 43bd65c973..80a3eb4f1c 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1283,18 +1283,6 @@ void tlb_set_page(CPUState *cpu, target_ulong vaddr, prot, mmu_idx, size); } -static inline ram_addr_t qemu_ram_addr_from_host_nofail(void *ptr) -{ - ram_addr_t ram_addr; - - ram_addr = qemu_ram_addr_from_host(ptr); - if (ram_addr == RAM_ADDR_INVALID) { - error_report("Bad ram pointer %p", ptr); - abort(); - } - return ram_addr; -} - /* * Note: tlb_fill() can trigger a resize of the TLB. This means that all of the * caller's prior references to the TLB table (e.g. CPUTLBEntry pointers) must diff --git a/softmmu/physmem.c b/softmmu/physmem.c index 50231bab30..56e03e07b5 100644 --- a/softmmu/physmem.c +++ b/softmmu/physmem.c @@ -2443,6 +2443,18 @@ ram_addr_t qemu_ram_addr_from_host(void *ptr) return block->offset + offset; } +ram_addr_t qemu_ram_addr_from_host_nofail(void *ptr) +{ + ram_addr_t ram_addr; + + ram_addr = qemu_ram_addr_from_host(ptr); + if (ram_addr == RAM_ADDR_INVALID) { + error_report("Bad ram pointer %p", ptr); + abort(); + } + return ram_addr; +} + static MemTxResult flatview_read(FlatView *fv, hwaddr addr, MemTxAttrs attrs, void *buf, hwaddr len); static MemTxResult flatview_write(FlatView *fv, hwaddr addr, MemTxAttrs attrs, From patchwork Tue Sep 6 08:38:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602967 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4346675mae; Tue, 6 Sep 2022 02:10:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR5mdPTcvyGjcdC2gHc1WP48DK2s/esnE56ZqlqcjZlZYaDs9ytxnat1Vqh5PXD7FfSzKhOr X-Received: by 2002:a0c:f307:0:b0:4aa:a431:c184 with SMTP id j7-20020a0cf307000000b004aaa431c184mr337826qvl.76.1662455406102; Tue, 06 Sep 2022 02:10:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662455406; cv=none; d=google.com; s=arc-20160816; b=m3TaYIHIEreCZxm5IUr9L5vwgmwnNSIQSwvkh9Krm8wFyTCA03HfBz1aVTI0lWBKKW MTD1G3/ckQZnlILu+aEMOBDqakLhxrf/zdsmR0kc2gejpiAb7Hd2+92wVls//YaWZbfk cbKKZHygDT+rwLdUVo9y64dJuS0kQp4ZVt82QkrnZ2NzAU1zpkNzuVYjgpdnqUDPaKg/ gomJwNhNAdyetnpCnVlpgnJB64rsduR0iAAx8JLJORipGMJjQXTrc1AsydiVc2r792L9 9GmgINUF8H16DK7C4Ogx1jQqZJ9YXFfrhEHkWD5glMj//90fNpox/IEBuMeFBgvyM8NM yTVA== 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=aenCwLhyHz+42ttancSjHI4JZk2Ya2FL+nx6M3jTwMg=; b=AM1eMkUKZKB531sOsV+Q973fIp5kBKfKPXffho2shYOhTrkv45VbpqCZG/wHtlk8Nl U5Jdim1bVJPykKwNBFg4NkP3f13WPpTN1g0lx4ftJAeDfXUgJgEy6DsbHOWnsIs47Mha Nu9V/GhkbqLwMPyaguIcto9SQLbpJ9iQ3x5s5tlbLMrunPq00BIZsriPZuB02YO5kh+D en4iNydhfYn43rLP+t/MIiHcBjiIX5jYJiRUUJP/H3rusT8fcpuCViErgNN0DIRmHlQt 8TU898h9/ajSskp2nQPPa42Skht3vASGaCuQtyvnNpmqX30c09vF2p4a4NjiQqO5NCZk 2pBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wy3USSW7; 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 h15-20020ac846cf000000b00304b825a7c6si5510129qto.66.2022.09.06.02.10.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 02:10:06 -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=wy3USSW7; 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]:53450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUar-0003kC-Kr for patch@linaro.org; Tue, 06 Sep 2022 05:10:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6N-0002hx-8G for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:35 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]:54234) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6L-0005XW-B8 for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:34 -0400 Received: by mail-wm1-x333.google.com with SMTP id h1so6462857wmd.3 for ; Tue, 06 Sep 2022 01:38:32 -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=aenCwLhyHz+42ttancSjHI4JZk2Ya2FL+nx6M3jTwMg=; b=wy3USSW76aYavO93m07j917YyBifQiuaHzXbg7cdn5BIbPMHe3OVS274KsAbXQuVsi 8W+Vo8SB1rUPWRAe9R50OSZLrzgxtRtPq+HrhgolSF044WsF8DYS9vqzs1/tyuJ5QmuG QkHcYJLQiLMzmg6T+FxvrqmcGAEyPGYmkzziVsouvYnMVNQvoXwUGfeMKbCkrvRtsvuU 46aZu1cMchW/oHo/kBMrRz1p1gii8Momsqoe7/7N5D/HJrYBB2h/EUp0r58uq+v7zpd2 vPhpw6z5XtDDcVNVkka7u1fcL1uf9hqROoORn5r2OBjEUkIYifwsq76BV+jrrw9f+jr9 9OBg== 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=aenCwLhyHz+42ttancSjHI4JZk2Ya2FL+nx6M3jTwMg=; b=IhtFaddm62fN1mLw7z9wstVE5/gPHt08KT2WNeZtwzJJavTl0S87K4A8lzh9xszebR 1zPTYy4whLTG27xFGhcalsZsiR10xfES2ezlmblXgAlaEh4+tJxYqfm5zlo7Q0aNyj5y kOnmEip3A/LyxrquPM6po/C1VTEw+niOY5WxwrXTPfrYVznfH5bakvGizEGi+qjVrRuE rdOm8iCpSX98cl7y/d3YYeoYCoPiJC0VubbVUo35Cbr9W+/POlUrVGI6spwi2av9OkMP Y0e89Swlttb9EtBasl0WbdNdUUjz90siT9223yQO7WYeqXbFlXU8/tGXDfOx/vSpJkGm PjDw== X-Gm-Message-State: ACgBeo0rZZzmRll1t/rtCcqa2PKfudVuB71GSojNZ/9WFMMXhkmsz5HZ H65x0ZXPukaGfEqprlm2YVfkfqFHBBDUFhsV X-Received: by 2002:a05:600c:3781:b0:3a6:804a:afc with SMTP id o1-20020a05600c378100b003a6804a0afcmr12769506wmr.27.1662453511984; Tue, 06 Sep 2022 01:38:31 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Ilya Leoshkevich Subject: [PULL v3 12/20] accel/tcg: Use probe_access_internal for softmmu get_page_addr_code_hostp Date: Tue, 6 Sep 2022 09:38:07 +0100 Message-Id: <20220906083815.252478-13-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::333; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x333.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" Simplify the implementation of get_page_addr_code_hostp by reusing the existing probe_access infrastructure. Acked-by: Ilya Leoshkevich Tested-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 76 ++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 50 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 80a3eb4f1c..8fad2d9b83 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1482,56 +1482,6 @@ static bool victim_tlb_hit(CPUArchState *env, size_t mmu_idx, size_t index, victim_tlb_hit(env, mmu_idx, index, offsetof(CPUTLBEntry, TY), \ (ADDR) & TARGET_PAGE_MASK) -/* - * Return a ram_addr_t for the virtual address for execution. - * - * Return -1 if we can't translate and execute from an entire page - * of RAM. This will force us to execute by loading and translating - * one insn at a time, without caching. - * - * NOTE: This function will trigger an exception if the page is - * not executable. - */ -tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, - void **hostp) -{ - uintptr_t mmu_idx = cpu_mmu_index(env, true); - uintptr_t index = tlb_index(env, mmu_idx, addr); - CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr); - void *p; - - if (unlikely(!tlb_hit(entry->addr_code, addr))) { - if (!VICTIM_TLB_HIT(addr_code, addr)) { - tlb_fill(env_cpu(env), addr, 0, MMU_INST_FETCH, mmu_idx, 0); - index = tlb_index(env, mmu_idx, addr); - entry = tlb_entry(env, mmu_idx, addr); - - if (unlikely(entry->addr_code & TLB_INVALID_MASK)) { - /* - * The MMU protection covers a smaller range than a target - * page, so we must redo the MMU check for every insn. - */ - return -1; - } - } - assert(tlb_hit(entry->addr_code, addr)); - } - - if (unlikely(entry->addr_code & TLB_MMIO)) { - /* The region is not backed by RAM. */ - if (hostp) { - *hostp = NULL; - } - return -1; - } - - p = (void *)((uintptr_t)addr + entry->addend); - if (hostp) { - *hostp = p; - } - return qemu_ram_addr_from_host_nofail(p); -} - static void notdirty_write(CPUState *cpu, vaddr mem_vaddr, unsigned size, CPUIOTLBEntry *iotlbentry, uintptr_t retaddr) { @@ -1687,6 +1637,32 @@ void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr, return flags ? NULL : host; } +/* + * Return a ram_addr_t for the virtual address for execution. + * + * Return -1 if we can't translate and execute from an entire page + * of RAM. This will force us to execute by loading and translating + * one insn at a time, without caching. + * + * NOTE: This function will trigger an exception if the page is + * not executable. + */ +tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, + void **hostp) +{ + void *p; + + (void)probe_access_internal(env, addr, 1, MMU_INST_FETCH, + cpu_mmu_index(env, true), false, &p, 0); + if (p == NULL) { + return -1; + } + if (hostp) { + *hostp = p; + } + return qemu_ram_addr_from_host_nofail(p); +} + #ifdef CONFIG_PLUGIN /* * Perform a TLB lookup and populate the qemu_plugin_hwaddr structure. From patchwork Tue Sep 6 08:38:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602960 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4339119mae; Tue, 6 Sep 2022 01:58:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR4tBuEsS9uWd1P8qlemMPqwAcUg9wRkUoTApQUvSNYPW+S1TP8qNnPfbGXBorXkHj1ieu1T X-Received: by 2002:ad4:5fc8:0:b0:49d:24d4:dc48 with SMTP id jq8-20020ad45fc8000000b0049d24d4dc48mr11554795qvb.111.1662454684157; Tue, 06 Sep 2022 01:58:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662454684; cv=none; d=google.com; s=arc-20160816; b=yN0COC3PuasCY29O2aYZZutHoyrRx3jwfzyuD1RHhCw+7swSGbda3TxKpQcH3TxeHr Ox0bQNjRju0E9CM7TZnJUWi5qQV6GvAgcYV4sW0aWVahOMX0BmK2YSZt4be96TrBVLeO uY4Z/L15OFbNgZTqGVnIMtB7saSG/PE0ztTvjVY/hB4q9BBjz+X0vgL7ssAjGQQbUDmQ 8nnrnkKJ3G+Z61+4z8zZw8g+JldjVF9FjhW9VyJy3J9F5F4+a8SAbyjGWu08O8YnhAPJ M6btSQRWSSlXwdRG+Cy8n1C+96DLZ/H2kIerrI3AYGPpun+fIZADLjOl9QpJPN1Mp/1N kyOg== 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=w1ES14kbaqz1aOCbKXN9PfcL6E/pNAFDrn35F0KK2iE=; b=04SjE05HWOnjFiiYPV6tJ4kKW4FZm3Kb6gFey7Ezvdtzu2ayEDBOeetuSQNH1vEmOL 9KQQIb2pm3MIW2iJCrC7iwJvFt2/iL3Ucxl1fCJ0uVaShjvaSfflTigAomajZuqkPCje P4FJCDGy9x+068U/XluUAx2NEzHMamSOB8f3Uu0U+K5JJv4ynTSDVwCcrsucKQM3xC4O lSRc/koyGuYzBcrKdkq33qsnxPaZlRsz/X9zr5VzQvPR5kItfGxKUoPkB3znj0yEvByK pF5zfuGumrh19U/4azYEBu0xX0gCWWw7mPxEKljzGFZg7SLvFuIx20MP2WTl+0K83l70 G7zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N5sQY1pW; 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 bk29-20020a05620a1a1d00b006b94066d884si7848359qkb.88.2022.09.06.01.58.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 01:58:04 -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=N5sQY1pW; 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]:53588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUPD-0003iV-NF for patch@linaro.org; Tue, 06 Sep 2022 04:58:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6P-0002lU-Ii for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:37 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:42750) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6M-0005YU-Oo for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:36 -0400 Received: by mail-wm1-x332.google.com with SMTP id d12-20020a05600c34cc00b003a83d20812fso7001876wmq.1 for ; Tue, 06 Sep 2022 01:38:34 -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=w1ES14kbaqz1aOCbKXN9PfcL6E/pNAFDrn35F0KK2iE=; b=N5sQY1pWRY8owwFdPYBrC/62I2osS14erujcW1Qo6jfvz8mwMF6AOekVliHsr8Ula+ ZqDuKlGQnO2zLznj35NU+3s3XT203hARb+8fWdnWDmzPgRnzcP3XSD/ayKdWeBu0iVun nwhsphe5IDkmKkImXm+EwyNU9DYlma3NM1MpPmWhAOai9Zm/7cp0Gu2mbOfgi3f3j+Oh rdkUiicheZW0wl44TP8iCJvTjukZNsLQPa7H3zK3RDWgv+l24YuLBc05PQr/t9klN9xC O2a3zzZy3OrsVRVV6ZmPteJgAYLVUpqOtE0JxjHh5JkUeOPL8JDIrJp6qFMhaSBgQR02 m57g== 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=w1ES14kbaqz1aOCbKXN9PfcL6E/pNAFDrn35F0KK2iE=; b=XXi8amKFGZOjrNNY2DSswxWuTYgILR/8T3a+IMgB+IiIFh4vlieC4Uy7N30bj0THII 4cAMO1IAAv5SySwrvRKeYOUF5FHyBeqixBOMm2oy3RFMbSTSKDEztSIfUPAC6m2qksRm GGtZh5KTXHv/0IhvfLiWDMa0qwyD7KFTkRm3D+ckc3rRMHItUy2Ir3ag524xQznYftVG MbkcVIyvbsWTZKpmbYew3KWC7pWOgewnGrNBQ+UZpnYBJy7tzMNMBctSJWaAkNZOFHk9 it2LLZNOUoNEJsfAJUBMnaoLiaPmXzdbimdrp1sTGRXh3bXT0iNYlLaBlyVbwwm+wOW7 JcOw== X-Gm-Message-State: ACgBeo2AiH6/WUh+N3LMQWVfY7mGDC6fnx24zWZtdDwFZBkdOUATGyCo UmBVE624uOF4LSu86W2m7l0de3+CUhOBbJTF X-Received: by 2002:a05:600c:1d14:b0:3a5:e8ba:f394 with SMTP id l20-20020a05600c1d1400b003a5e8baf394mr12966136wms.137.1662453512931; Tue, 06 Sep 2022 01:38:32 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Ilya Leoshkevich Subject: [PULL v3 13/20] accel/tcg: Document the faulting lookup in tb_lookup_cmp Date: Tue, 6 Sep 2022 09:38:08 +0100 Message-Id: <20220906083815.252478-14-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::332; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x332.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" It was non-obvious to me why we can raise an exception in the middle of a comparison function, but it works. While nearby, use TARGET_PAGE_ALIGN instead of open-coding. Acked-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- accel/tcg/cpu-exec.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 7887af6f45..5f43b9769a 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -198,7 +198,16 @@ static bool tb_lookup_cmp(const void *p, const void *d) tb_page_addr_t phys_page2; target_ulong virt_page2; - virt_page2 = (desc->pc & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; + /* + * We know that the first page matched, and an otherwise valid TB + * encountered an incomplete instruction at the end of that page, + * therefore we know that generating a new TB from the current PC + * must also require reading from the next page -- even if the + * second pages do not match, and therefore the resulting insn + * is different for the new TB. Therefore any exception raised + * here by the faulting lookup is not premature. + */ + virt_page2 = TARGET_PAGE_ALIGN(desc->pc); phys_page2 = get_page_addr_code(desc->env, virt_page2); if (tb->page_addr[1] == phys_page2) { return true; From patchwork Tue Sep 6 08:38:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602964 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4343672mae; Tue, 6 Sep 2022 02:04:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR7TPiHMp47K4B9IDXytxw5yq0sBwbmcTo0dGNPUODxSXnTWeeQYp9LzWxQ8sNrtKNkMAbRL X-Received: by 2002:a05:620a:4482:b0:6bb:c315:9597 with SMTP id x2-20020a05620a448200b006bbc3159597mr35251576qkp.423.1662455090454; Tue, 06 Sep 2022 02:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662455090; cv=none; d=google.com; s=arc-20160816; b=IxFQFvWD0P/0ogILdXQUq/r4Vae0Ugos/gPR66RQqDfK5ILIcHlNspIYkDzDo3rR8d DHMIe8uVxlt5rFjrw0KD4GDrbCHtbIo/YsiPI1wC9qM2iauGgVz7GhozEilp6uJXkpnL iS6cr4UgBa1IjwynR3+R6SpGMiO3Lz4mf4+dO1MHc8dGbhJXs7eaqDaRHukTDbglThHv dITsexsq1TIZWQMLYr++oid44EkfRtXdGrKKAKAtd8iz62WKrBWs2Otwi1osURnDN1jI +eMlF1YClO38l+Ftbi7wIHW7B8EaPm7oI7nJn5PjSQqRH59w2T4mJHAigm9ipy6RTq77 QxrA== 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=L6+S1C4verjHBqz/uuyCgreQuy1xnosEZw7oND6E5kE=; b=XWgImiPgK7kUUGM+lhMUwSlFMpa+H4KlLpxp4TzfFEEcUKi3yol4W8TMRnfn1d58Vk v1P9gCuMUiOfOoHSJeKwMhfJWDttkR1lQAfsFjPsha53+v2/LkMvGbpJfm36Xfzlgxur +QdQG7aRGY1mM0YMJgqkydfYYvehau13kUWiCepShWuHlktWJY+SC+HQOoL2d2uNEbCH YbAQWRjedi1JM/H+rgxbLz88ZUgY13NGX2P7bfbDlqAERtIFgxkaFp/YFUJ0InYiZ6qW Qv9BlQ27f+lj/WWxkuuYTDD7COSaA+xTJMhsHcLKSLwalO4urD0t6EDKMrPbZoKjxLx2 iWMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=py4fuwOk; 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 k13-20020a05620a414d00b006bb4eb9510dsi8173965qko.302.2022.09.06.02.04.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 02:04: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=py4fuwOk; 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]:49630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUVl-0001nW-SM for patch@linaro.org; Tue, 06 Sep 2022 05:04:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35406) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6P-0002mH-Qi for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:37 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:36854) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6N-0005UN-1z for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:37 -0400 Received: by mail-wr1-x434.google.com with SMTP id b17so958877wrq.3 for ; Tue, 06 Sep 2022 01:38:34 -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=L6+S1C4verjHBqz/uuyCgreQuy1xnosEZw7oND6E5kE=; b=py4fuwOk3Eww8ZsdFM971XDyRZTjmxi6/uG+RgzwhD5Y4GvZ1N0CfOYROs576LaC1n Yt8Id4NezKVSXmcBoTfDuRnWU6YP5NHqj8JObkTEE4xid5F1NMHHixXAwqOH6yckoJGY Mwnl6PahBumBoyHh4raLrV9GEVctgjF4CAprVwJWvpLf6demCmup6eMMlJabSyW19sQ8 1GnWt0Tw8TnSQ1lhgoCyqu6gwHFalNXJemg3vgo3g59Ixb+OdYUE1yqUE6r/m+xhgGkn 0hbuPNugZdxa0ls9GJmZNfI/Cm6R/fdZkt5Bqx4jOrY7DPr8+9/Lv+rP3rz5+MyPZ6FH +IVw== 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=L6+S1C4verjHBqz/uuyCgreQuy1xnosEZw7oND6E5kE=; b=2XxtGvzGE3cuzhg7xgoHIxg3J+JXrztejo9Vq4cTAO6NyMDhIZecAdmmwOu8gu3jvs Butov/MJv6RYBUfc+anT/sbwWX57eGuSIfsYWlTVr64vGMxlT/0RoHlrUkc5ugTfnnAN jLxCzHWSmGM9AX49sT5I3R41FcnDaKcvYegeKz0tO+bmqBHDFHnkRQA6+T4LNCEhuOV5 zX1jA8e2zIeqO70vrnXLL7VO8nh4cKMeMokqFihguJXwv7bmkb9hm0GDjtwUjYq3XCHx D1JPsDFDOsfnO1kfieau3QW//ucQRyC7QUkieaQN6ESANeC+I1Lq1zs1Ry0p6iRZ5BIM gzVg== X-Gm-Message-State: ACgBeo3DkmGPfnzBlglPvAO1/WbRv7NC7fgiEsDsa+kB7B2ACHxw60bi 5dgAE1rve8OvvRcjIhjJzw4ppilItKVzmsHm X-Received: by 2002:a5d:584f:0:b0:226:edcd:b467 with SMTP id i15-20020a5d584f000000b00226edcdb467mr15281518wrf.363.1662453514337; Tue, 06 Sep 2022 01:38:34 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Alistair Francis , Ilya Leoshkevich Subject: [PULL v3 14/20] accel/tcg: Remove translator_ldsw Date: Tue, 6 Sep 2022 09:38:09 +0100 Message-Id: <20220906083815.252478-15-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::434; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x434.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" The only user can easily use translator_lduw and adjust the type to signed during the return. Reviewed-by: Alistair Francis Acked-by: Ilya Leoshkevich Tested-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- include/exec/translator.h | 1 - target/i386/tcg/translate.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/include/exec/translator.h b/include/exec/translator.h index 0d0bf3a31e..45b9268ca4 100644 --- a/include/exec/translator.h +++ b/include/exec/translator.h @@ -178,7 +178,6 @@ bool translator_use_goto_tb(DisasContextBase *db, target_ulong dest); #define FOR_EACH_TRANSLATOR_LD(F) \ F(translator_ldub, uint8_t, cpu_ldub_code, /* no swap */) \ - F(translator_ldsw, int16_t, cpu_ldsw_code, bswap16) \ F(translator_lduw, uint16_t, cpu_lduw_code, bswap16) \ F(translator_ldl, uint32_t, cpu_ldl_code, bswap32) \ F(translator_ldq, uint64_t, cpu_ldq_code, bswap64) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index fc081e6ad6..983439d926 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -2033,7 +2033,7 @@ static inline uint8_t x86_ldub_code(CPUX86State *env, DisasContext *s) static inline int16_t x86_ldsw_code(CPUX86State *env, DisasContext *s) { - return translator_ldsw(env, &s->base, advance_pc(env, s, 2)); + return translator_lduw(env, &s->base, advance_pc(env, s, 2)); } static inline uint16_t x86_lduw_code(CPUX86State *env, DisasContext *s) From patchwork Tue Sep 6 08:38:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602966 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4346620mae; Tue, 6 Sep 2022 02:10:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR5l+371UtKSRdBxK3gvOds/nGC+0xmQDE358PPMRvpdXE9UgfLcCjXyuffh32C9BdMI6y5X X-Received: by 2002:a0c:e3c7:0:b0:473:7d9a:6237 with SMTP id e7-20020a0ce3c7000000b004737d9a6237mr43126601qvl.37.1662455401042; Tue, 06 Sep 2022 02:10:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662455401; cv=none; d=google.com; s=arc-20160816; b=0Pg0BQXGYyDTWgdd27QAsfgt/A+oRmm437vqaKY6Cf7JwZmUm85ukHBfVZzc2cQFB4 Rx1NC856M8Sp2EBd3GFpZNuAFDnym565aoFk7uucVH7usBY9pQCG/DReLdZ+fD8usvFm p5XQcX21KSckn5ixXKvcGJnRTzuzTAg1+PwhE4yuhhAGvRZyaYzA82yLkqx9c7qZYouv be/0zxzbMObTqhutaxA+g1Qh3YQShlTodbvFnZ8yihzR7HBFl2Y79YSWnCaibw+UM8tZ LX42AcEVr7dT/KQKeHt36j7SJ2c/bHYt2XMN4yleP7ToU0oPeQ9Vre3CntZ3p5Y50VXk 18LQ== 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=9wHymMXUbW+Le666NoJ9m0zaXjlOxfaJKBXKYJDHRGg=; b=vk4EeDH5RwoZU5mCxiEh0ytEeUmPCus9I/E51bhnGSD7UWsxpSWNR1Q5vzI2RA59tz cypk6iwjMZ5Fm9oNsaT//hKGH8sXwiGs887N/ehc/hOW5AuaCdYwulXffjfMJirXBYKC MlBYWfhIzpbcZXszjbEGKiLKJyg6dgzLCxtszckHuS2m59ohJooPUhLg0tnNxiK/rNiD yhcj0W98tptN6S/L2ECwcub7/eoyABfEZvMGdtVKzX9EPFM57x7CRQg9geJGeCcCwEgM O52exFK+9o8r5DBVw/FzUy4ANMY4rWfvnHFA0G/3R7SQEJR7qqOnCLnqJsERJD2VUaW9 Dw2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ofiKkdCJ; 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 r7-20020a056214212700b004991e162fa4si5748186qvc.220.2022.09.06.02.10.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 02:10: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=ofiKkdCJ; 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]:53448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUam-0003i7-GO for patch@linaro.org; Tue, 06 Sep 2022 05:10:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6T-0002sl-9Q for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:41 -0400 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:56238) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6Q-0005aA-7V for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:40 -0400 Received: by mail-wm1-x32f.google.com with SMTP id d5so6464531wms.5 for ; Tue, 06 Sep 2022 01:38:37 -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=9wHymMXUbW+Le666NoJ9m0zaXjlOxfaJKBXKYJDHRGg=; b=ofiKkdCJ3/+xheHaF1jIh54mOfgIN+KD2vR271dchErBZDI4mbVmpIzm18ryWF68Mf uDbAWGuvHUIYrPqrGuh2Gy4i0rVflqgAwCsqkxvxMmdJLywfyCz6qECGfZdTS8Uz6Tj3 bsLQ/kqh7pnzI7DRGvPuyohWXmmm+0GkqSi3TjWxLruMRjHWRrzFnqrHSVM89y51Ah0U qensEoVIaFo8FAEGd1LL2pCGuJZT1lsCsFZ6DLimVC8Xd6n92pVRyyzklR4wE9171A3S CDFqbTF3JU9JR0dVRAkkLc5M9swOPbS7OOtl4SujCfE95Eh6DayhupkdZX+QhgxuCjAh GNQA== 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=9wHymMXUbW+Le666NoJ9m0zaXjlOxfaJKBXKYJDHRGg=; b=cM4ITtpWDJTevgwHcWBuP0+C2GoafhVUPimkms1ZJZE0eYdYDDwCbBs/m8TRL7QwQy FLZu7ZBC/AWh+QY5dgWrgFZVXGS2VsxbufBriawzu10GY5QR5uBHaDdV1ZYF2Sk0bJzn peEh24/X5+g/viVvp6gnhoqCUPFgKIqN2Og8aD0Ao05IFiEKeJNQSAY+H/qolUf5XdWN 7AHieSt61emU8SfQpK5n1irAZAKnjtOTL2WyFnoRns61Gza44tRHZtv9qHvtCkigNHxM fY33v3trZQ9kzryVEHhl3roDP3RaIMX4Ds/BExjQJaB2uj8syut0SxlktSQ+1jpM6JWY ychg== X-Gm-Message-State: ACgBeo2vQf8FTFiIczQKb3yLHynWq0j8jXk5ff40jIWxJ+C2U/9NBd8i sjyvW5IhBmcdyv9BytxLLSuM79QCLyDInkXP X-Received: by 2002:a05:600c:3c83:b0:3a6:7719:60ea with SMTP id bg3-20020a05600c3c8300b003a6771960eamr12625028wmb.105.1662453515656; Tue, 06 Sep 2022 01:38:35 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Alistair Francis , Ilya Leoshkevich Subject: [PULL v3 15/20] accel/tcg: Add pc and host_pc params to gen_intermediate_code Date: Tue, 6 Sep 2022 09:38:10 +0100 Message-Id: <20220906083815.252478-16-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::32f; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32f.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" Pass these along to translator_loop -- pc may be used instead of tb->pc, and host_pc is currently unused. Adjust all targets at one time. Acked-by: Alistair Francis Acked-by: Ilya Leoshkevich Tested-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- include/exec/exec-all.h | 1 - include/exec/translator.h | 24 ++++++++++++++++++++---- accel/tcg/translate-all.c | 6 ++++-- accel/tcg/translator.c | 9 +++++---- target/alpha/translate.c | 5 +++-- target/arm/translate.c | 5 +++-- target/avr/translate.c | 5 +++-- target/cris/translate.c | 5 +++-- target/hexagon/translate.c | 6 ++++-- target/hppa/translate.c | 5 +++-- target/i386/tcg/translate.c | 5 +++-- target/loongarch/translate.c | 6 ++++-- target/m68k/translate.c | 5 +++-- target/microblaze/translate.c | 5 +++-- target/mips/tcg/translate.c | 5 +++-- target/nios2/translate.c | 5 +++-- target/openrisc/translate.c | 6 ++++-- target/ppc/translate.c | 5 +++-- target/riscv/translate.c | 5 +++-- target/rx/translate.c | 5 +++-- target/s390x/tcg/translate.c | 5 +++-- target/sh4/translate.c | 5 +++-- target/sparc/translate.c | 5 +++-- target/tricore/translate.c | 6 ++++-- target/xtensa/translate.c | 6 ++++-- 25 files changed, 97 insertions(+), 53 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 9f35e3b7a9..bcad607c4e 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -39,7 +39,6 @@ typedef ram_addr_t tb_page_addr_t; #define TB_PAGE_ADDR_FMT RAM_ADDR_FMT #endif -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns); void restore_state_to_opc(CPUArchState *env, TranslationBlock *tb, target_ulong *data); diff --git a/include/exec/translator.h b/include/exec/translator.h index 45b9268ca4..69db0f5c21 100644 --- a/include/exec/translator.h +++ b/include/exec/translator.h @@ -26,6 +26,19 @@ #include "exec/translate-all.h" #include "tcg/tcg.h" +/** + * gen_intermediate_code + * @cpu: cpu context + * @tb: translation block + * @max_insns: max number of instructions to translate + * @pc: guest virtual program counter address + * @host_pc: host physical program counter address + * + * This function must be provided by the target, which should create + * the target-specific DisasContext, and then invoke translator_loop. + */ +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc); /** * DisasJumpType: @@ -123,11 +136,13 @@ typedef struct TranslatorOps { /** * translator_loop: - * @ops: Target-specific operations. - * @db: Disassembly context. * @cpu: Target vCPU. * @tb: Translation block. * @max_insns: Maximum number of insns to translate. + * @pc: guest virtual program counter address + * @host_pc: host physical program counter address + * @ops: Target-specific operations. + * @db: Disassembly context. * * Generic translator loop. * @@ -141,8 +156,9 @@ typedef struct TranslatorOps { * - When single-stepping is enabled (system-wide or on the current vCPU). * - When too many instructions have been translated. */ -void translator_loop(const TranslatorOps *ops, DisasContextBase *db, - CPUState *cpu, TranslationBlock *tb, int max_insns); +void translator_loop(CPUState *cpu, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc, + const TranslatorOps *ops, DisasContextBase *db); void translator_loop_temp_check(DisasContextBase *db); diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index b83161a081..587886aa4e 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -46,6 +46,7 @@ #include "exec/cputlb.h" #include "exec/translate-all.h" +#include "exec/translator.h" #include "qemu/bitmap.h" #include "qemu/qemu-print.h" #include "qemu/timer.h" @@ -1392,11 +1393,12 @@ TranslationBlock *tb_gen_code(CPUState *cpu, TCGProfile *prof = &tcg_ctx->prof; int64_t ti; #endif + void *host_pc; assert_memory_lock(); qemu_thread_jit_write(); - phys_pc = get_page_addr_code(env, pc); + phys_pc = get_page_addr_code_hostp(env, pc, &host_pc); if (phys_pc == -1) { /* Generate a one-shot TB with 1 insn in it */ @@ -1444,7 +1446,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tcg_func_start(tcg_ctx); tcg_ctx->cpu = env_cpu(env); - gen_intermediate_code(cpu, tb, max_insns); + gen_intermediate_code(cpu, tb, max_insns, pc, host_pc); assert(tb->size != 0); tcg_ctx->cpu = NULL; max_insns = tb->icount; diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index fe7af9b943..3eef30d93a 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -51,16 +51,17 @@ static inline void translator_page_protect(DisasContextBase *dcbase, #endif } -void translator_loop(const TranslatorOps *ops, DisasContextBase *db, - CPUState *cpu, TranslationBlock *tb, int max_insns) +void translator_loop(CPUState *cpu, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc, + const TranslatorOps *ops, DisasContextBase *db) { uint32_t cflags = tb_cflags(tb); bool plugin_enabled; /* Initialize DisasContext */ db->tb = tb; - db->pc_first = tb->pc; - db->pc_next = db->pc_first; + db->pc_first = pc; + db->pc_next = pc; db->is_jmp = DISAS_NEXT; db->num_insns = 0; db->max_insns = max_insns; diff --git a/target/alpha/translate.c b/target/alpha/translate.c index 9af1627079..6766350f56 100644 --- a/target/alpha/translate.c +++ b/target/alpha/translate.c @@ -3043,10 +3043,11 @@ static const TranslatorOps alpha_tr_ops = { .disas_log = alpha_tr_disas_log, }; -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext dc; - translator_loop(&alpha_tr_ops, &dc.base, cpu, tb, max_insns); + translator_loop(cpu, tb, max_insns, pc, host_pc, &alpha_tr_ops, &dc.base); } void restore_state_to_opc(CPUAlphaState *env, TranslationBlock *tb, diff --git a/target/arm/translate.c b/target/arm/translate.c index ad617b9948..9474e4b44b 100644 --- a/target/arm/translate.c +++ b/target/arm/translate.c @@ -9892,7 +9892,8 @@ static const TranslatorOps thumb_translator_ops = { }; /* generate intermediate code for basic block 'tb'. */ -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext dc = { }; const TranslatorOps *ops = &arm_translator_ops; @@ -9907,7 +9908,7 @@ void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) } #endif - translator_loop(ops, &dc.base, cpu, tb, max_insns); + translator_loop(cpu, tb, max_insns, pc, host_pc, ops, &dc.base); } void restore_state_to_opc(CPUARMState *env, TranslationBlock *tb, diff --git a/target/avr/translate.c b/target/avr/translate.c index 026753c963..e65b6008c0 100644 --- a/target/avr/translate.c +++ b/target/avr/translate.c @@ -3049,10 +3049,11 @@ static const TranslatorOps avr_tr_ops = { .disas_log = avr_tr_disas_log, }; -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext dc = { }; - translator_loop(&avr_tr_ops, &dc.base, cs, tb, max_insns); + translator_loop(cs, tb, max_insns, pc, host_pc, &avr_tr_ops, &dc.base); } void restore_state_to_opc(CPUAVRState *env, TranslationBlock *tb, diff --git a/target/cris/translate.c b/target/cris/translate.c index ac101344a3..73385b0b3c 100644 --- a/target/cris/translate.c +++ b/target/cris/translate.c @@ -3286,10 +3286,11 @@ static const TranslatorOps cris_tr_ops = { .disas_log = cris_tr_disas_log, }; -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext dc; - translator_loop(&cris_tr_ops, &dc.base, cs, tb, max_insns); + translator_loop(cs, tb, max_insns, pc, host_pc, &cris_tr_ops, &dc.base); } void cris_cpu_dump_state(CPUState *cs, FILE *f, int flags) diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c index d4fc92f7e9..0e8a0772f7 100644 --- a/target/hexagon/translate.c +++ b/target/hexagon/translate.c @@ -850,11 +850,13 @@ static const TranslatorOps hexagon_tr_ops = { .disas_log = hexagon_tr_disas_log, }; -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext ctx; - translator_loop(&hexagon_tr_ops, &ctx.base, cs, tb, max_insns); + translator_loop(cs, tb, max_insns, pc, host_pc, + &hexagon_tr_ops, &ctx.base); } #define NAME_LEN 64 diff --git a/target/hppa/translate.c b/target/hppa/translate.c index b8dbfee5e9..8b861957e0 100644 --- a/target/hppa/translate.c +++ b/target/hppa/translate.c @@ -4340,10 +4340,11 @@ static const TranslatorOps hppa_tr_ops = { .disas_log = hppa_tr_disas_log, }; -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext ctx; - translator_loop(&hppa_tr_ops, &ctx.base, cs, tb, max_insns); + translator_loop(cs, tb, max_insns, pc, host_pc, &hppa_tr_ops, &ctx.base); } void restore_state_to_opc(CPUHPPAState *env, TranslationBlock *tb, diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 983439d926..ba2ab2b45d 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -8821,11 +8821,12 @@ static const TranslatorOps i386_tr_ops = { }; /* generate intermediate code for basic block 'tb'. */ -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext dc; - translator_loop(&i386_tr_ops, &dc.base, cpu, tb, max_insns); + translator_loop(cpu, tb, max_insns, pc, host_pc, &i386_tr_ops, &dc.base); } void restore_state_to_opc(CPUX86State *env, TranslationBlock *tb, diff --git a/target/loongarch/translate.c b/target/loongarch/translate.c index 51ba291430..95b37ea180 100644 --- a/target/loongarch/translate.c +++ b/target/loongarch/translate.c @@ -241,11 +241,13 @@ static const TranslatorOps loongarch_tr_ops = { .disas_log = loongarch_tr_disas_log, }; -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext ctx; - translator_loop(&loongarch_tr_ops, &ctx.base, cs, tb, max_insns); + translator_loop(cs, tb, max_insns, pc, host_pc, + &loongarch_tr_ops, &ctx.base); } void loongarch_translate_init(void) diff --git a/target/m68k/translate.c b/target/m68k/translate.c index 8f3c298ad0..5098f7e570 100644 --- a/target/m68k/translate.c +++ b/target/m68k/translate.c @@ -6361,10 +6361,11 @@ static const TranslatorOps m68k_tr_ops = { .disas_log = m68k_tr_disas_log, }; -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext dc; - translator_loop(&m68k_tr_ops, &dc.base, cpu, tb, max_insns); + translator_loop(cpu, tb, max_insns, pc, host_pc, &m68k_tr_ops, &dc.base); } static double floatx80_to_double(CPUM68KState *env, uint16_t high, uint64_t low) diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c index bf01384d33..c5546f93aa 100644 --- a/target/microblaze/translate.c +++ b/target/microblaze/translate.c @@ -1849,10 +1849,11 @@ static const TranslatorOps mb_tr_ops = { .disas_log = mb_tr_disas_log, }; -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext dc; - translator_loop(&mb_tr_ops, &dc.base, cpu, tb, max_insns); + translator_loop(cpu, tb, max_insns, pc, host_pc, &mb_tr_ops, &dc.base); } void mb_cpu_dump_state(CPUState *cs, FILE *f, int flags) diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c index de1511baaf..0d936e2648 100644 --- a/target/mips/tcg/translate.c +++ b/target/mips/tcg/translate.c @@ -16155,11 +16155,12 @@ static const TranslatorOps mips_tr_ops = { .disas_log = mips_tr_disas_log, }; -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext ctx; - translator_loop(&mips_tr_ops, &ctx.base, cs, tb, max_insns); + translator_loop(cs, tb, max_insns, pc, host_pc, &mips_tr_ops, &ctx.base); } void mips_tcg_init(void) diff --git a/target/nios2/translate.c b/target/nios2/translate.c index 3a037a68cc..c588e8e885 100644 --- a/target/nios2/translate.c +++ b/target/nios2/translate.c @@ -1038,10 +1038,11 @@ static const TranslatorOps nios2_tr_ops = { .disas_log = nios2_tr_disas_log, }; -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext dc; - translator_loop(&nios2_tr_ops, &dc.base, cs, tb, max_insns); + translator_loop(cs, tb, max_insns, pc, host_pc, &nios2_tr_ops, &dc.base); } void nios2_cpu_dump_state(CPUState *cs, FILE *f, int flags) diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c index 7b8ad43d5f..8154f9d744 100644 --- a/target/openrisc/translate.c +++ b/target/openrisc/translate.c @@ -1705,11 +1705,13 @@ static const TranslatorOps openrisc_tr_ops = { .disas_log = openrisc_tr_disas_log, }; -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext ctx; - translator_loop(&openrisc_tr_ops, &ctx.base, cs, tb, max_insns); + translator_loop(cs, tb, max_insns, pc, host_pc, + &openrisc_tr_ops, &ctx.base); } void openrisc_cpu_dump_state(CPUState *cs, FILE *f, int flags) diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 388337f81b..000b1e518d 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -7719,11 +7719,12 @@ static const TranslatorOps ppc_tr_ops = { .disas_log = ppc_tr_disas_log, }; -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext ctx; - translator_loop(&ppc_tr_ops, &ctx.base, cs, tb, max_insns); + translator_loop(cs, tb, max_insns, pc, host_pc, &ppc_tr_ops, &ctx.base); } void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 63b04e8a94..38666ddc91 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1196,11 +1196,12 @@ static const TranslatorOps riscv_tr_ops = { .disas_log = riscv_tr_disas_log, }; -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext ctx; - translator_loop(&riscv_tr_ops, &ctx.base, cs, tb, max_insns); + translator_loop(cs, tb, max_insns, pc, host_pc, &riscv_tr_ops, &ctx.base); } void riscv_translate_init(void) diff --git a/target/rx/translate.c b/target/rx/translate.c index 62aee66937..ea5653bc95 100644 --- a/target/rx/translate.c +++ b/target/rx/translate.c @@ -2363,11 +2363,12 @@ static const TranslatorOps rx_tr_ops = { .disas_log = rx_tr_disas_log, }; -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext dc; - translator_loop(&rx_tr_ops, &dc.base, cs, tb, max_insns); + translator_loop(cs, tb, max_insns, pc, host_pc, &rx_tr_ops, &dc.base); } void restore_state_to_opc(CPURXState *env, TranslationBlock *tb, diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c index e2ee005671..d4c0b9b3a2 100644 --- a/target/s390x/tcg/translate.c +++ b/target/s390x/tcg/translate.c @@ -6676,11 +6676,12 @@ static const TranslatorOps s390x_tr_ops = { .disas_log = s390x_tr_disas_log, }; -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext dc; - translator_loop(&s390x_tr_ops, &dc.base, cs, tb, max_insns); + translator_loop(cs, tb, max_insns, pc, host_pc, &s390x_tr_ops, &dc.base); } void restore_state_to_opc(CPUS390XState *env, TranslationBlock *tb, diff --git a/target/sh4/translate.c b/target/sh4/translate.c index f1b190e7cf..01056571c3 100644 --- a/target/sh4/translate.c +++ b/target/sh4/translate.c @@ -2368,11 +2368,12 @@ static const TranslatorOps sh4_tr_ops = { .disas_log = sh4_tr_disas_log, }; -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext ctx; - translator_loop(&sh4_tr_ops, &ctx.base, cs, tb, max_insns); + translator_loop(cs, tb, max_insns, pc, host_pc, &sh4_tr_ops, &ctx.base); } void restore_state_to_opc(CPUSH4State *env, TranslationBlock *tb, diff --git a/target/sparc/translate.c b/target/sparc/translate.c index 2e28222d31..2cbbe2396a 100644 --- a/target/sparc/translate.c +++ b/target/sparc/translate.c @@ -5917,11 +5917,12 @@ static const TranslatorOps sparc_tr_ops = { .disas_log = sparc_tr_disas_log, }; -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext dc = {}; - translator_loop(&sparc_tr_ops, &dc.base, cs, tb, max_insns); + translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base); } void sparc_tcg_init(void) diff --git a/target/tricore/translate.c b/target/tricore/translate.c index d170500fa5..a0558ead71 100644 --- a/target/tricore/translate.c +++ b/target/tricore/translate.c @@ -8878,10 +8878,12 @@ static const TranslatorOps tricore_tr_ops = { }; -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext ctx; - translator_loop(&tricore_tr_ops, &ctx.base, cs, tb, max_insns); + translator_loop(cs, tb, max_insns, pc, host_pc, + &tricore_tr_ops, &ctx.base); } void diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index 70e11eeb45..8b864ef925 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -1279,10 +1279,12 @@ static const TranslatorOps xtensa_translator_ops = { .disas_log = xtensa_tr_disas_log, }; -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, + target_ulong pc, void *host_pc) { DisasContext dc = {}; - translator_loop(&xtensa_translator_ops, &dc.base, cpu, tb, max_insns); + translator_loop(cpu, tb, max_insns, pc, host_pc, + &xtensa_translator_ops, &dc.base); } void xtensa_cpu_dump_state(CPUState *cs, FILE *f, int flags) From patchwork Tue Sep 6 08:38:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602963 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4340636mae; Tue, 6 Sep 2022 02:00:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR6KkLh+d5hl/ntvfq5NIXF59zzXngxptPLRrvHWAA6FaWXkTtT3E5/dm3plwNwWC2B8QKkJ X-Received: by 2002:a37:b483:0:b0:6b5:8688:5299 with SMTP id d125-20020a37b483000000b006b586885299mr35136740qkf.147.1662454854261; Tue, 06 Sep 2022 02:00:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662454854; cv=none; d=google.com; s=arc-20160816; b=PEv4HdwEzzCc2WGnSbPH4ynW3PjOOSkZfrJbaj6gu3gDEVgoZBW4Ut6gca0Cs+6XQz xMFr/ne+vD06BHzcE44FWV+fXM0XArcS8YbhHC3FTScFCp1OCZoiQ7vNk9SG1cdTCrF9 INOAAgWtR0ARPGxWEDR+9K4J3qDQage8AR3ICL0Q7ifbGvFtnU7NhiX2eLNkAMk5s4ft UFp7vdHtSRX1DOTAEJ6LGgZiKbcP4qitYBuJ/6f6AfjeRpYA0M2Sr6IhO4bkcaoyipu9 Sz24Vw0wyC0L4UK+D7Fa1pZbvNfoB7h/orq6camKSgUZhvqGSW6dVQftJngTbtuHBrOT wePw== 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=gk2Ija1gWhhe3TrBGaxA21/0RuEaoEB/ncK0Mv2tFOk=; b=xLDZ5C6maIVUcwzB7nFuL54zdgsqoT2owqRKPOabuy215WknluXLY2OvNMfDcsVJHo mHglN/NXBhrJORbq7f/B4e/P78jtpPFO4qZy3YHUQFBse1dSINNndFjie/KSj/0iQhq9 yYjOrvzxIv2fsDbma/swmw2DjUom+iy5AqEMJjPwpDCbWGTMbKYPMl+wVaFKeYZQsk4m holixSmDnGQ3IL5vX3/Gqdtep6yCvA4PcAYXa2SrnKlawpQ+8GGfSpa/Vxv09yoepcjH ZSVODTnhV/zYxrN+1WmScb1RYa2LIdOOblw/Bih5XePr0LOJP0BG+BuGrNFSGjxtlV8e uiZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j7FUMkub; 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 fb11-20020a05622a480b00b003192a70cb93si7126407qtb.127.2022.09.06.02.00.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 02:00: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=j7FUMkub; 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]:56172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVURx-0005OD-LY for patch@linaro.org; Tue, 06 Sep 2022 05:00:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35408) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6S-0002sV-Pn for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:40 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]:51747) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6Q-0005aR-Cx for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:40 -0400 Received: by mail-wm1-x335.google.com with SMTP id ay12so6480485wmb.1 for ; Tue, 06 Sep 2022 01:38:37 -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=gk2Ija1gWhhe3TrBGaxA21/0RuEaoEB/ncK0Mv2tFOk=; b=j7FUMkubLBPJ2b3Y0MTR1IRNpcdrHZbMH+AgfworDZeKUQiGcXugqhNe7kOVk4Ma4E 1qfD8C6CzS7m3RR5mrlef1nkMK+NV5SwF3PkLDC1YL+7NaLV5phdmeLYdRv0zLGNDVJK uSkgWNln7SDSUWMsbQ8kP9I4Gu65P05m50fS71WfW6HymjzHHDLxxj+CHvYbkO9Mgpl9 gbmPsLZsQzfar5A4Y5523UxbsU1aAIMRof/MoyOLjQ1AQxyRKegnqiZJjhz6xVU7ZWAs luhTJmgyg7iAGObMNvsltZs+680W9ZR+POQTWOZsrO8Zk0cSx2/Qc8kGqpcQf5HNCPa+ m7QQ== 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=gk2Ija1gWhhe3TrBGaxA21/0RuEaoEB/ncK0Mv2tFOk=; b=03jSy1R1iJ6vfhnESWNgU+aqsU2w2l6EJbJ1vvkjzo3NVcm7zD6THOQgiOah2XgukC mzhsja7+CAWeYwHyEMfad99lK6OUlcZjApFAOBoNeDiy8HxZ2vnr9eW9MoVqhAzUA220 zErtaOabv2piQy5zTJC5jVwAOUtyPeGla+/GoGOpwJ+a9Es2A3D4OpXA8aFYfKuQHwwl iciZKMcNs52UNqmQUXRVdvCc2QfRdt3NgWdPyPPGs3I+u24n12qt5AlFy7dsScftZ+1z Rtgx+nLt0D046SZo5CUe9Hx3azwUShvATznZmv06hNSdQSm5iRhUusaSVa5IFUZooKeO IjvQ== X-Gm-Message-State: ACgBeo1ZirwvoNhJgCid9KPPi2f/JEBDplykHUPnGuDyXUyHziAUma5G OQFTPl+MYaUCBRlGTIzofgW7jvvSKMwZ+T9B X-Received: by 2002:a7b:ce09:0:b0:3a6:6561:d9d5 with SMTP id m9-20020a7bce09000000b003a66561d9d5mr13048588wmc.62.1662453516941; Tue, 06 Sep 2022 01:38:36 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Ilya Leoshkevich Subject: [PULL v3 16/20] accel/tcg: Add fast path for translator_ld* Date: Tue, 6 Sep 2022 09:38:11 +0100 Message-Id: <20220906083815.252478-17-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::335; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x335.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" Cache the translation from guest to host address, so we may use direct loads when we hit on the primary translation page. Look up the second translation page only once, during translation. This obviates another lookup of the second page within tb_gen_code after translation. Fixes a bug in that plugin_insn_append should be passed the bytes in the original memory order, not bswapped by pieces. Acked-by: Ilya Leoshkevich Tested-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- include/exec/translator.h | 63 +++++++++++-------- accel/tcg/translate-all.c | 23 +++---- accel/tcg/translator.c | 126 +++++++++++++++++++++++++++++--------- 3 files changed, 141 insertions(+), 71 deletions(-) diff --git a/include/exec/translator.h b/include/exec/translator.h index 69db0f5c21..3b77f5f4aa 100644 --- a/include/exec/translator.h +++ b/include/exec/translator.h @@ -81,24 +81,14 @@ typedef enum DisasJumpType { * Architecture-agnostic disassembly context. */ typedef struct DisasContextBase { - const TranslationBlock *tb; + TranslationBlock *tb; target_ulong pc_first; target_ulong pc_next; DisasJumpType is_jmp; int num_insns; int max_insns; bool singlestep_enabled; -#ifdef CONFIG_USER_ONLY - /* - * Guest address of the last byte of the last protected page. - * - * Pages containing the translated instructions are made non-writable in - * order to achieve consistency in case another thread is modifying the - * code while translate_insn() fetches the instruction bytes piecemeal. - * Such writer threads are blocked on mmap_lock() in page_unprotect(). - */ - target_ulong page_protect_end; -#endif + void *host_addr[2]; } DisasContextBase; /** @@ -183,24 +173,43 @@ bool translator_use_goto_tb(DisasContextBase *db, target_ulong dest); * the relevant information at translation time. */ -#define GEN_TRANSLATOR_LD(fullname, type, load_fn, swap_fn) \ - type fullname ## _swap(CPUArchState *env, DisasContextBase *dcbase, \ - abi_ptr pc, bool do_swap); \ - static inline type fullname(CPUArchState *env, \ - DisasContextBase *dcbase, abi_ptr pc) \ - { \ - return fullname ## _swap(env, dcbase, pc, false); \ +uint8_t translator_ldub(CPUArchState *env, DisasContextBase *db, abi_ptr pc); +uint16_t translator_lduw(CPUArchState *env, DisasContextBase *db, abi_ptr pc); +uint32_t translator_ldl(CPUArchState *env, DisasContextBase *db, abi_ptr pc); +uint64_t translator_ldq(CPUArchState *env, DisasContextBase *db, abi_ptr pc); + +static inline uint16_t +translator_lduw_swap(CPUArchState *env, DisasContextBase *db, + abi_ptr pc, bool do_swap) +{ + uint16_t ret = translator_lduw(env, db, pc); + if (do_swap) { + ret = bswap16(ret); } + return ret; +} -#define FOR_EACH_TRANSLATOR_LD(F) \ - F(translator_ldub, uint8_t, cpu_ldub_code, /* no swap */) \ - F(translator_lduw, uint16_t, cpu_lduw_code, bswap16) \ - F(translator_ldl, uint32_t, cpu_ldl_code, bswap32) \ - F(translator_ldq, uint64_t, cpu_ldq_code, bswap64) +static inline uint32_t +translator_ldl_swap(CPUArchState *env, DisasContextBase *db, + abi_ptr pc, bool do_swap) +{ + uint32_t ret = translator_ldl(env, db, pc); + if (do_swap) { + ret = bswap32(ret); + } + return ret; +} -FOR_EACH_TRANSLATOR_LD(GEN_TRANSLATOR_LD) - -#undef GEN_TRANSLATOR_LD +static inline uint64_t +translator_ldq_swap(CPUArchState *env, DisasContextBase *db, + abi_ptr pc, bool do_swap) +{ + uint64_t ret = translator_ldq(env, db, pc); + if (do_swap) { + ret = bswap64(ret); + } + return ret; +} /* * Return whether addr is on the same page as where disassembly started. diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 587886aa4e..f5e8592d4a 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1385,8 +1385,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu, { CPUArchState *env = cpu->env_ptr; TranslationBlock *tb, *existing_tb; - tb_page_addr_t phys_pc, phys_page2; - target_ulong virt_page2; + tb_page_addr_t phys_pc; tcg_insn_unit *gen_code_buf; int gen_code_size, search_size, max_insns; #ifdef CONFIG_PROFILER @@ -1429,6 +1428,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu, tb->flags = flags; tb->cflags = cflags; tb->trace_vcpu_dstate = *cpu->trace_dstate; + tb->page_addr[0] = phys_pc; + tb->page_addr[1] = -1; tcg_ctx->tb_cflags = cflags; tb_overflow: @@ -1622,13 +1623,11 @@ TranslationBlock *tb_gen_code(CPUState *cpu, } /* - * If the TB is not associated with a physical RAM page then - * it must be a temporary one-insn TB, and we have nothing to do - * except fill in the page_addr[] fields. Return early before - * attempting to link to other TBs or add to the lookup table. + * If the TB is not associated with a physical RAM page then it must be + * a temporary one-insn TB, and we have nothing left to do. Return early + * before attempting to link to other TBs or add to the lookup table. */ - if (phys_pc == -1) { - tb->page_addr[0] = tb->page_addr[1] = -1; + if (tb->page_addr[0] == -1) { return tb; } @@ -1639,17 +1638,11 @@ TranslationBlock *tb_gen_code(CPUState *cpu, */ tcg_tb_insert(tb); - /* check next page if needed */ - virt_page2 = (pc + tb->size - 1) & TARGET_PAGE_MASK; - phys_page2 = -1; - if ((pc & TARGET_PAGE_MASK) != virt_page2) { - phys_page2 = get_page_addr_code(env, virt_page2); - } /* * No explicit memory barrier is required -- tb_link_page() makes the * TB visible in a consistent state. */ - existing_tb = tb_link_page(tb, phys_pc, phys_page2); + existing_tb = tb_link_page(tb, tb->page_addr[0], tb->page_addr[1]); /* if the TB already exists, discard what we just translated */ if (unlikely(existing_tb != tb)) { uintptr_t orig_aligned = (uintptr_t)gen_code_buf; diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 3eef30d93a..ca8a5f2d83 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -42,15 +42,6 @@ bool translator_use_goto_tb(DisasContextBase *db, target_ulong dest) return ((db->pc_first ^ dest) & TARGET_PAGE_MASK) == 0; } -static inline void translator_page_protect(DisasContextBase *dcbase, - target_ulong pc) -{ -#ifdef CONFIG_USER_ONLY - dcbase->page_protect_end = pc | ~TARGET_PAGE_MASK; - page_protect(pc); -#endif -} - void translator_loop(CPUState *cpu, TranslationBlock *tb, int max_insns, target_ulong pc, void *host_pc, const TranslatorOps *ops, DisasContextBase *db) @@ -66,7 +57,12 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int max_insns, db->num_insns = 0; db->max_insns = max_insns; db->singlestep_enabled = cflags & CF_SINGLE_STEP; - translator_page_protect(db, db->pc_next); + db->host_addr[0] = host_pc; + db->host_addr[1] = NULL; + +#ifdef CONFIG_USER_ONLY + page_protect(pc); +#endif ops->init_disas_context(db, cpu); tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ @@ -151,31 +147,103 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int max_insns, #endif } -static inline void translator_maybe_page_protect(DisasContextBase *dcbase, - target_ulong pc, size_t len) +static void *translator_access(CPUArchState *env, DisasContextBase *db, + target_ulong pc, size_t len) { -#ifdef CONFIG_USER_ONLY - target_ulong end = pc + len - 1; + void *host; + target_ulong base, end; + TranslationBlock *tb; - if (end > dcbase->page_protect_end) { - translator_page_protect(dcbase, end); + tb = db->tb; + + /* Use slow path if first page is MMIO. */ + if (unlikely(tb->page_addr[0] == -1)) { + return NULL; } + + end = pc + len - 1; + if (likely(is_same_page(db, end))) { + host = db->host_addr[0]; + base = db->pc_first; + } else { + host = db->host_addr[1]; + base = TARGET_PAGE_ALIGN(db->pc_first); + if (host == NULL) { + tb->page_addr[1] = + get_page_addr_code_hostp(env, base, &db->host_addr[1]); +#ifdef CONFIG_USER_ONLY + page_protect(end); #endif + /* We cannot handle MMIO as second page. */ + assert(tb->page_addr[1] != -1); + host = db->host_addr[1]; + } + + /* Use slow path when crossing pages. */ + if (is_same_page(db, pc)) { + return NULL; + } + } + + tcg_debug_assert(pc >= base); + return host + (pc - base); } -#define GEN_TRANSLATOR_LD(fullname, type, load_fn, swap_fn) \ - type fullname ## _swap(CPUArchState *env, DisasContextBase *dcbase, \ - abi_ptr pc, bool do_swap) \ - { \ - translator_maybe_page_protect(dcbase, pc, sizeof(type)); \ - type ret = load_fn(env, pc); \ - if (do_swap) { \ - ret = swap_fn(ret); \ - } \ - plugin_insn_append(pc, &ret, sizeof(ret)); \ - return ret; \ +uint8_t translator_ldub(CPUArchState *env, DisasContextBase *db, abi_ptr pc) +{ + uint8_t ret; + void *p = translator_access(env, db, pc, sizeof(ret)); + + if (p) { + plugin_insn_append(pc, p, sizeof(ret)); + return ldub_p(p); } + ret = cpu_ldub_code(env, pc); + plugin_insn_append(pc, &ret, sizeof(ret)); + return ret; +} -FOR_EACH_TRANSLATOR_LD(GEN_TRANSLATOR_LD) +uint16_t translator_lduw(CPUArchState *env, DisasContextBase *db, abi_ptr pc) +{ + uint16_t ret, plug; + void *p = translator_access(env, db, pc, sizeof(ret)); -#undef GEN_TRANSLATOR_LD + if (p) { + plugin_insn_append(pc, p, sizeof(ret)); + return lduw_p(p); + } + ret = cpu_lduw_code(env, pc); + plug = tswap16(ret); + plugin_insn_append(pc, &plug, sizeof(ret)); + return ret; +} + +uint32_t translator_ldl(CPUArchState *env, DisasContextBase *db, abi_ptr pc) +{ + uint32_t ret, plug; + void *p = translator_access(env, db, pc, sizeof(ret)); + + if (p) { + plugin_insn_append(pc, p, sizeof(ret)); + return ldl_p(p); + } + ret = cpu_ldl_code(env, pc); + plug = tswap32(ret); + plugin_insn_append(pc, &plug, sizeof(ret)); + return ret; +} + +uint64_t translator_ldq(CPUArchState *env, DisasContextBase *db, abi_ptr pc) +{ + uint64_t ret, plug; + void *p = translator_access(env, db, pc, sizeof(ret)); + + if (p) { + plugin_insn_append(pc, p, sizeof(ret)); + return ldq_p(p); + } + ret = cpu_ldq_code(env, pc); + plug = tswap64(ret); + plugin_insn_append(pc, &plug, sizeof(ret)); + return ret; +} From patchwork Tue Sep 6 08:38:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602969 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4350991mae; Tue, 6 Sep 2022 02:17:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR7/fEKTU5yd4o6dCvQxfLaDSWosrm6xMI2x2Wn8KvZiZOGcU18DfW9/2sYVqR5eXV6jtfYS X-Received: by 2002:a05:622a:11c6:b0:344:54b8:6382 with SMTP id n6-20020a05622a11c600b0034454b86382mr41664957qtk.571.1662455833820; Tue, 06 Sep 2022 02:17:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662455833; cv=none; d=google.com; s=arc-20160816; b=x/8MPvHmbVAPkZ8zwFbImbO2FPdUNbPIiidRasy2mHxFdWXqC6lTJ5rNMXUgbPWsEY 34u2pf3fUGcFPAg5uuG+rEqRiB5+PwSbj+aRJxcnc6G22Uj2ty8Yo9omkInmh0pCd19Y OTtJjWJ1Xr02NRSlePofAVa1mJ9T+2LWULsPgoPq5pPNSD7dREFIbmHBQHPde13Agpwf U5MJpDby67bpcJAerXLZzFQevcSna0T68/4tMenxIGZqnJxSeCByTsZtgCosolaHl7qw GZfNji2rx1evU5SWcuNLktlsLmwBG8Hy2uEh1B9gzfyvcBIDjDEJUyTvswoic+3jeqbr cTNQ== 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=ma8Zb7C/D5E9n4vs/B/KW4yUla4VOnseIE7w6pS63kM=; b=mqNF3/WWOWBXOGEV9zmepRkjBpqAVeIGzYe31HGhztjiJxXmCnoZk0kew0f5lq7XRh tPceMHknMe9eKX0kHJ5DEvnYfowzgyiBdLeXjwL1XbK0ebndnIhJcMe/6MpR0NRpYgiq QRiLwW+qMpCqxzF9LaMgKQSjwsnXryV8TjrnNUKjLa0lsiRVhnLVddgcUmFngk2b66oI Kz+ECTvtEhqrJQbRUmUDtuFaFd5zNvdd6B/rukXiOrEKDwVc8blc8iG7CbpNM+iOldkJ uLBawrZriZgLsE63iKzoxrf186kPMm+/LkmU+suQT29noemhyKychjHDthtuhzbfEjvQ 53XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yFs0OFRN; 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 i185-20020a37b8c2000000b006b88d06dc1csi5845812qkf.565.2022.09.06.02.17.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 02:17:13 -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=yFs0OFRN; 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]:46830 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUhl-0001TS-4N for patch@linaro.org; Tue, 06 Sep 2022 05:17:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6U-0002v1-Re for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:42 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:41544) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6R-0005ag-Kf for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:42 -0400 Received: by mail-wr1-x435.google.com with SMTP id t14so7022078wrx.8 for ; Tue, 06 Sep 2022 01:38:39 -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=ma8Zb7C/D5E9n4vs/B/KW4yUla4VOnseIE7w6pS63kM=; b=yFs0OFRNAupATt+6l1Y+x7M44x0272+K9PuwGgXgqHo2cekEmFbSO5KlVu8Wt9ssGP YtIpB1V/d0gELgapUwmTnkzBXh8glmijB9+9wxLbN1IScBjtqh999hr8Q2xQsOLvNdYa T9R6YXZoOdnChcQkgOhdscrKYwdL5uvyRv+9QJrQCoNVgPUnq7Xh5ZaLrnC4BUYycRVM ZJHRtGba3FjgzJ/B1RgSxbPTQhDFTMM4U4tDXjQZFPVmGQBp1dasqIA27fbjSjVWIiFH 0tpLEY3cCXT5MfPwEn4CtUqYa+LJGXrthEAERt6rx9zLw2tXcnK5ohQEgc0Z1BOqYbU1 Jirw== 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=ma8Zb7C/D5E9n4vs/B/KW4yUla4VOnseIE7w6pS63kM=; b=mx3N21Rux9TCG0jOBBetwAfdjCfhyLVmDawQpPcN2qPrahfILpYsmXYMmPwXirqTp2 5tx0pGVACoZoW1ifq5PO+DbO960bpZtK2lo9p9p+5J9UCdxuDaUaigs8e5a9cfJMvjGx LYSVObkoq+WzZGN3m/R4rlCMhlaIzfrnFwg6T86Jc0Fh1OX08ZzrDFq58qELyMa1eSQ/ MAp1zYIuT5s6urNH6pVkWGoxj8/uBxNgzWQ72+bRq5WSLDc2fg1ArRWFIhQtPcctAMUw uOttkkJdmmjGQqzBncraFnUNpegiSvu7hHrPrE3LLNvHNIC4WwwvG3bpCp2rsBc2U6ZN aMRA== X-Gm-Message-State: ACgBeo3jhEiUacxY+Mrie7STgDJBMrAR4rh7+vwe+S7QqAdti0stKW0R HFDf2XBFodOsA6f52eJvvE6N1DhbA/qE5984 X-Received: by 2002:a5d:6e88:0:b0:225:3d19:addf with SMTP id k8-20020a5d6e88000000b002253d19addfmr26046546wrz.600.1662453517935; Tue, 06 Sep 2022 01:38:37 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Ilya Leoshkevich Subject: [PULL v3 17/20] target/s390x: Make translator stop before the end of a page Date: Tue, 6 Sep 2022 09:38:12 +0100 Message-Id: <20220906083815.252478-18-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::435; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-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, 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" From: Ilya Leoshkevich Right now translator stops right *after* the end of a page, which breaks reporting of fault locations when the last instruction of a multi-insn translation block crosses a page boundary. Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson Message-Id: <20220817150506.592862-3-iii@linux.ibm.com> Signed-off-by: Richard Henderson --- target/s390x/tcg/translate.c | 15 +++- tests/tcg/s390x/noexec.c | 106 +++++++++++++++++++++++ tests/tcg/multiarch/noexec.c.inc | 139 +++++++++++++++++++++++++++++++ tests/tcg/s390x/Makefile.target | 1 + 4 files changed, 257 insertions(+), 4 deletions(-) create mode 100644 tests/tcg/s390x/noexec.c create mode 100644 tests/tcg/multiarch/noexec.c.inc diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c index d4c0b9b3a2..1d2dddab1c 100644 --- a/target/s390x/tcg/translate.c +++ b/target/s390x/tcg/translate.c @@ -6609,6 +6609,14 @@ static void s390x_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) dc->insn_start = tcg_last_op(); } +static target_ulong get_next_pc(CPUS390XState *env, DisasContext *s, + uint64_t pc) +{ + uint64_t insn = ld_code2(env, s, pc); + + return pc + get_ilen((insn >> 8) & 0xff); +} + static void s390x_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) { CPUS390XState *env = cs->env_ptr; @@ -6616,10 +6624,9 @@ static void s390x_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) dc->base.is_jmp = translate_one(env, dc); if (dc->base.is_jmp == DISAS_NEXT) { - uint64_t page_start; - - page_start = dc->base.pc_first & TARGET_PAGE_MASK; - if (dc->base.pc_next - page_start >= TARGET_PAGE_SIZE || dc->ex_value) { + if (!is_same_page(dcbase, dc->base.pc_next) || + !is_same_page(dcbase, get_next_pc(env, dc, dc->base.pc_next)) || + dc->ex_value) { dc->base.is_jmp = DISAS_TOO_MANY; } } diff --git a/tests/tcg/s390x/noexec.c b/tests/tcg/s390x/noexec.c new file mode 100644 index 0000000000..15d007d07f --- /dev/null +++ b/tests/tcg/s390x/noexec.c @@ -0,0 +1,106 @@ +#include "../multiarch/noexec.c.inc" + +static void *arch_mcontext_pc(const mcontext_t *ctx) +{ + return (void *)ctx->psw.addr; +} + +static int arch_mcontext_arg(const mcontext_t *ctx) +{ + return ctx->gregs[2]; +} + +static void arch_flush(void *p, int len) +{ +} + +extern char noexec_1[]; +extern char noexec_2[]; +extern char noexec_end[]; + +asm("noexec_1:\n" + " lgfi %r2,1\n" /* %r2 is 0 on entry, set 1. */ + "noexec_2:\n" + " lgfi %r2,2\n" /* %r2 is 0/1; set 2. */ + " br %r14\n" /* return */ + "noexec_end:"); + +extern char exrl_1[]; +extern char exrl_2[]; +extern char exrl_end[]; + +asm("exrl_1:\n" + " exrl %r0, exrl_2\n" + " br %r14\n" + "exrl_2:\n" + " lgfi %r2,2\n" + "exrl_end:"); + +int main(void) +{ + struct noexec_test noexec_tests[] = { + { + .name = "fallthrough", + .test_code = noexec_1, + .test_len = noexec_end - noexec_1, + .page_ofs = noexec_1 - noexec_2, + .entry_ofs = noexec_1 - noexec_2, + .expected_si_ofs = 0, + .expected_pc_ofs = 0, + .expected_arg = 1, + }, + { + .name = "jump", + .test_code = noexec_1, + .test_len = noexec_end - noexec_1, + .page_ofs = noexec_1 - noexec_2, + .entry_ofs = 0, + .expected_si_ofs = 0, + .expected_pc_ofs = 0, + .expected_arg = 0, + }, + { + .name = "exrl", + .test_code = exrl_1, + .test_len = exrl_end - exrl_1, + .page_ofs = exrl_1 - exrl_2, + .entry_ofs = exrl_1 - exrl_2, + .expected_si_ofs = 0, + .expected_pc_ofs = exrl_1 - exrl_2, + .expected_arg = 0, + }, + { + .name = "fallthrough [cross]", + .test_code = noexec_1, + .test_len = noexec_end - noexec_1, + .page_ofs = noexec_1 - noexec_2 - 2, + .entry_ofs = noexec_1 - noexec_2 - 2, + .expected_si_ofs = 0, + .expected_pc_ofs = -2, + .expected_arg = 1, + }, + { + .name = "jump [cross]", + .test_code = noexec_1, + .test_len = noexec_end - noexec_1, + .page_ofs = noexec_1 - noexec_2 - 2, + .entry_ofs = -2, + .expected_si_ofs = 0, + .expected_pc_ofs = -2, + .expected_arg = 0, + }, + { + .name = "exrl [cross]", + .test_code = exrl_1, + .test_len = exrl_end - exrl_1, + .page_ofs = exrl_1 - exrl_2 - 2, + .entry_ofs = exrl_1 - exrl_2 - 2, + .expected_si_ofs = 0, + .expected_pc_ofs = exrl_1 - exrl_2 - 2, + .expected_arg = 0, + }, + }; + + return test_noexec(noexec_tests, + sizeof(noexec_tests) / sizeof(noexec_tests[0])); +} diff --git a/tests/tcg/multiarch/noexec.c.inc b/tests/tcg/multiarch/noexec.c.inc new file mode 100644 index 0000000000..2ef539b721 --- /dev/null +++ b/tests/tcg/multiarch/noexec.c.inc @@ -0,0 +1,139 @@ +/* + * Common code for arch-specific MMU_INST_FETCH fault testing. + */ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Forward declarations. */ + +static void *arch_mcontext_pc(const mcontext_t *ctx); +static int arch_mcontext_arg(const mcontext_t *ctx); +static void arch_flush(void *p, int len); + +/* Testing infrastructure. */ + +struct noexec_test { + const char *name; + const char *test_code; + int test_len; + int page_ofs; + int entry_ofs; + int expected_si_ofs; + int expected_pc_ofs; + int expected_arg; +}; + +static void *page_base; +static int page_size; +static const struct noexec_test *current_noexec_test; + +static void handle_err(const char *syscall) +{ + printf("[ FAILED ] %s: %s\n", syscall, strerror(errno)); + exit(EXIT_FAILURE); +} + +static void handle_segv(int sig, siginfo_t *info, void *ucontext) +{ + const struct noexec_test *test = current_noexec_test; + const mcontext_t *mc = &((ucontext_t *)ucontext)->uc_mcontext; + void *expected_si; + void *expected_pc; + void *pc; + int arg; + + if (test == NULL) { + printf("[ FAILED ] unexpected SEGV\n"); + exit(EXIT_FAILURE); + } + current_noexec_test = NULL; + + expected_si = page_base + test->expected_si_ofs; + if (info->si_addr != expected_si) { + printf("[ FAILED ] wrong si_addr (%p != %p)\n", + info->si_addr, expected_si); + exit(EXIT_FAILURE); + } + + pc = arch_mcontext_pc(mc); + expected_pc = page_base + test->expected_pc_ofs; + if (pc != expected_pc) { + printf("[ FAILED ] wrong pc (%p != %p)\n", pc, expected_pc); + exit(EXIT_FAILURE); + } + + arg = arch_mcontext_arg(mc); + if (arg != test->expected_arg) { + printf("[ FAILED ] wrong arg (%d != %d)\n", arg, test->expected_arg); + exit(EXIT_FAILURE); + } + + if (mprotect(page_base, page_size, + PROT_READ | PROT_WRITE | PROT_EXEC) < 0) { + handle_err("mprotect"); + } +} + +static void test_noexec_1(const struct noexec_test *test) +{ + void *start = page_base + test->page_ofs; + void (*fn)(int arg) = page_base + test->entry_ofs; + + memcpy(start, test->test_code, test->test_len); + arch_flush(start, test->test_len); + + /* Trigger TB creation in order to test invalidation. */ + fn(0); + + if (mprotect(page_base, page_size, PROT_NONE) < 0) { + handle_err("mprotect"); + } + + /* Trigger SEGV and check that handle_segv() ran. */ + current_noexec_test = test; + fn(0); + assert(current_noexec_test == NULL); +} + +static int test_noexec(struct noexec_test *tests, size_t n_tests) +{ + struct sigaction act; + size_t i; + + memset(&act, 0, sizeof(act)); + act.sa_sigaction = handle_segv; + act.sa_flags = SA_SIGINFO; + if (sigaction(SIGSEGV, &act, NULL) < 0) { + handle_err("sigaction"); + } + + page_size = getpagesize(); + page_base = mmap(NULL, 2 * page_size, + PROT_READ | PROT_WRITE | PROT_EXEC, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (page_base == MAP_FAILED) { + handle_err("mmap"); + } + page_base += page_size; + + for (i = 0; i < n_tests; i++) { + struct noexec_test *test = &tests[i]; + + printf("[ RUN ] %s\n", test->name); + test_noexec_1(test); + printf("[ OK ]\n"); + } + + printf("[ PASSED ]\n"); + return EXIT_SUCCESS; +} diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target index 1a7a4a2f59..5e13a41c3f 100644 --- a/tests/tcg/s390x/Makefile.target +++ b/tests/tcg/s390x/Makefile.target @@ -16,6 +16,7 @@ TESTS+=shift TESTS+=trap TESTS+=signals-s390x TESTS+=branch-relative-long +TESTS+=noexec Z14_TESTS=vfminmax vfminmax: LDFLAGS+=-lm From patchwork Tue Sep 6 08:38:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602961 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4339191mae; Tue, 6 Sep 2022 01:58:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR7BIJV8FfVxfBzlOeR0ULIU5gvhTHNse9uKFsfPOg+SAY+2QhsgvWZYUwZB+PzhFHbpeP1n X-Received: by 2002:a05:622a:647:b0:344:6015:63ee with SMTP id a7-20020a05622a064700b00344601563eemr43550636qtb.346.1662454693480; Tue, 06 Sep 2022 01:58:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662454693; cv=none; d=google.com; s=arc-20160816; b=VLfgRuxLkcQGbb4u+NqCJ1JVNnyobLTHjiNemr91tp1EihNh9d+MB+l0pV5GUyh6+q g/I7URt+JBWjht+um9TjW9osW5kspMdb9pTZ5jOh5K5X3WNiIaeZhvQOsdhn8wKjUFNZ 5kia0E6NMKupVfmur4/b6Byys7Ac57KGgF8v333W3wCDU/mbaa075CL7f9Y7EQs1nR0F z6zUDx1F1vvXxpP3hLjmM8Rg3+d+7sVPBXTd8j0xry3rvwDfMdgExdlX1ZjQaKHwnlz6 n7i4mSWtCgi5Jfy0Ww8NAwU4/0NkT/Tdk1elGTozDBZ40H8qXQtRCSl5HDnBcOLCVKKP BUmg== 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=X6/RjTe1C8StJRf4AyHl6TXZ/FCc2+SmQ7gfSYyrc4c=; b=kYP1XcXbqceBa+E9f8y37kR+xoOr26uQJ47s82AqfMUqYS+d1cDwwsCYxShMrkwFzL pKjuqopiYGLvvURMyIpTK+KwIIyJph6XIkM730Z4v1R/ubarsRK3YuumYq2v2uXzJ+TA 6XUmiQ9/VcpHWAO2CopeBgIJoQYcNuG0+lFEAoYJE712+GiOq/Zd4zMlYyjULxONpLE9 w75hIbKuWVsWQ0hPc3+k38zmYOLT/9sVmDrCtH4rnaTdgjmHAkIpJS6rwZOnlK7LP9E8 t0gyXRQR1XZh3gv4H5mMxrxn3OCkgbJpv/X7svTz7J07DUufsONLMwhd8ThRx5k7jsP/ Ezxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="BzI/uPL7"; 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 s1-20020a05622a018100b00357173148b8si354146qtw.478.2022.09.06.01.58.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 01:58:13 -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="BzI/uPL7"; 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]:58886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUPM-00042t-UP for patch@linaro.org; Tue, 06 Sep 2022 04:58:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6U-0002uz-Qt for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:42 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:42958) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6S-0005SJ-7w for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:42 -0400 Received: by mail-wr1-x42b.google.com with SMTP id bp20so13828164wrb.9 for ; Tue, 06 Sep 2022 01:38:39 -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=X6/RjTe1C8StJRf4AyHl6TXZ/FCc2+SmQ7gfSYyrc4c=; b=BzI/uPL7i/W42jvKqmUZ6CM6xI/X+qrlrrHwO3pcUC7Cqc/dIgeUB7/FjtcRe9gzZG ZCq2fsUXWEvSTQPCvhgFCh573EMCvwajJ9xbFOIwaSfjbyIM8+aP+rum51NTduVrkb63 +FJ/DGhdS/PuvxFRL8FT683ZFkWTMRoTBnfay7dIurqWSEFzRWw114SyZvPtclfMY/55 dI9eEuVYTOzI7Z24FuO+RsLLjmDwzbUE1ZU+qTakzqLTm3bwVDdj0kkoi3tnP8p52pj+ cgW21NOodFXNpiNTa0zcLmr9axqGvIhYvvXO9rSPQ3Ur1yrRx7SJ6auv6BYmLi+g55rN 4n2A== 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=X6/RjTe1C8StJRf4AyHl6TXZ/FCc2+SmQ7gfSYyrc4c=; b=nVXF4xqrOHwzHeomWfzr+ozLoV9ZwNwU3GJJghqZGQd6O+F8C5A1ZcPTxGNGqu2pXC sQS/1mVQqMAmTLJfeliHfr+BIX6uZkoNZpq2+HMG/3P/boUJJoC5uEiknVSTF1nHzgx5 tS/Bg+WU5AtiKMQfKS1gJdCt+fm764zh8GMzAHvMB8olxAsWzQwxKpdifKvFmwoTaQX8 ldLUdtnPmHESO+PNJhgIgTjmA0W6707sjfh8MxN5eHb78sMXWq6FvxPxFEeMsjtaoxE6 CpQCp9kdSPYzwfR0GJ2crtGt7TbqGO5rLEHB4U8EWnaa8MJ9HQGthH9T+fGZJGYSj1t8 5suw== X-Gm-Message-State: ACgBeo3HGgmZQUED76MuA03fW5Bgd5ibOztFcTu+116FJ8CgkSSLJeRO WqYatD/7qLgJ4/RS6NRgIWCDokmv5BzH+9jB X-Received: by 2002:a05:6000:1867:b0:21f:f2cf:74a8 with SMTP id d7-20020a056000186700b0021ff2cf74a8mr26909364wri.344.1662453519432; Tue, 06 Sep 2022 01:38:39 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Ilya Leoshkevich Subject: [PULL v3 18/20] target/i386: Make translator stop before the end of a page Date: Tue, 6 Sep 2022 09:38:13 +0100 Message-Id: <20220906083815.252478-19-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::42b; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42b.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" From: Ilya Leoshkevich Right now translator stops right *after* the end of a page, which breaks reporting of fault locations when the last instruction of a multi-insn translation block crosses a page boundary. An implementation, like the one arm and s390x have, would require an i386 length disassembler, which is burdensome to maintain. Another alternative would be to single-step at the end of a guest page, but this may come with a performance impact. Fix by snapshotting disassembly state and restoring it after we figure out we crossed a page boundary. This includes rolling back cc_op updates and emitted ops. Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1143 Message-Id: <20220817150506.592862-4-iii@linux.ibm.com> [rth: Simplify end-of-insn cross-page checks.] Signed-off-by: Richard Henderson --- target/i386/tcg/translate.c | 64 ++++++++++++++++----------- tests/tcg/x86_64/noexec.c | 75 ++++++++++++++++++++++++++++++++ tests/tcg/x86_64/Makefile.target | 3 +- 3 files changed, 116 insertions(+), 26 deletions(-) create mode 100644 tests/tcg/x86_64/noexec.c diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index ba2ab2b45d..d6420df31d 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -130,6 +130,7 @@ typedef struct DisasContext { TCGv_i64 tmp1_i64; sigjmp_buf jmpbuf; + TCGOp *prev_insn_end; } DisasContext; /* The environment in which user-only runs is constrained. */ @@ -2008,6 +2009,12 @@ static uint64_t advance_pc(CPUX86State *env, DisasContext *s, int num_bytes) { uint64_t pc = s->pc; + /* This is a subsequent insn that crosses a page boundary. */ + if (s->base.num_insns > 1 && + !is_same_page(&s->base, s->pc + num_bytes - 1)) { + siglongjmp(s->jmpbuf, 2); + } + s->pc += num_bytes; if (unlikely(s->pc - s->pc_start > X86_MAX_INSN_LENGTH)) { /* If the instruction's 16th byte is on a different page than the 1st, a @@ -4669,6 +4676,8 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) int modrm, reg, rm, mod, op, opreg, val; target_ulong next_eip, tval; target_ulong pc_start = s->base.pc_next; + bool orig_cc_op_dirty = s->cc_op_dirty; + CCOp orig_cc_op = s->cc_op; s->pc_start = s->pc = pc_start; s->override = -1; @@ -4681,9 +4690,22 @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) s->rip_offset = 0; /* for relative ip address */ s->vex_l = 0; s->vex_v = 0; - if (sigsetjmp(s->jmpbuf, 0) != 0) { + switch (sigsetjmp(s->jmpbuf, 0)) { + case 0: + break; + case 1: gen_exception_gpf(s); return s->pc; + case 2: + /* Restore state that may affect the next instruction. */ + s->cc_op_dirty = orig_cc_op_dirty; + s->cc_op = orig_cc_op; + s->base.num_insns--; + tcg_remove_ops_after(s->prev_insn_end); + s->base.is_jmp = DISAS_TOO_MANY; + return pc_start; + default: + g_assert_not_reached(); } prefixes = 0; @@ -8745,6 +8767,7 @@ static void i386_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu) { DisasContext *dc = container_of(dcbase, DisasContext, base); + dc->prev_insn_end = tcg_last_op(); tcg_gen_insn_start(dc->base.pc_next, dc->cc_op); } @@ -8765,31 +8788,22 @@ static void i386_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) #endif pc_next = disas_insn(dc, cpu); - - if (dc->flags & (HF_TF_MASK | HF_INHIBIT_IRQ_MASK)) { - /* if single step mode, we generate only one instruction and - generate an exception */ - /* if irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear - the flag and abort the translation to give the irqs a - chance to happen */ - dc->base.is_jmp = DISAS_TOO_MANY; - } else if ((tb_cflags(dc->base.tb) & CF_USE_ICOUNT) - && ((pc_next & TARGET_PAGE_MASK) - != ((pc_next + TARGET_MAX_INSN_SIZE - 1) - & TARGET_PAGE_MASK) - || (pc_next & ~TARGET_PAGE_MASK) == 0)) { - /* Do not cross the boundary of the pages in icount mode, - it can cause an exception. Do it only when boundary is - crossed by the first instruction in the block. - If current instruction already crossed the bound - it's ok, - because an exception hasn't stopped this code. - */ - dc->base.is_jmp = DISAS_TOO_MANY; - } else if ((pc_next - dc->base.pc_first) >= (TARGET_PAGE_SIZE - 32)) { - dc->base.is_jmp = DISAS_TOO_MANY; - } - dc->base.pc_next = pc_next; + + if (dc->base.is_jmp == DISAS_NEXT) { + if (dc->flags & (HF_TF_MASK | HF_INHIBIT_IRQ_MASK)) { + /* + * If single step mode, we generate only one instruction and + * generate an exception. + * If irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear + * the flag and abort the translation to give the irqs a + * chance to happen. + */ + dc->base.is_jmp = DISAS_TOO_MANY; + } else if (!is_same_page(&dc->base, pc_next)) { + dc->base.is_jmp = DISAS_TOO_MANY; + } + } } static void i386_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) diff --git a/tests/tcg/x86_64/noexec.c b/tests/tcg/x86_64/noexec.c new file mode 100644 index 0000000000..9b124901be --- /dev/null +++ b/tests/tcg/x86_64/noexec.c @@ -0,0 +1,75 @@ +#include "../multiarch/noexec.c.inc" + +static void *arch_mcontext_pc(const mcontext_t *ctx) +{ + return (void *)ctx->gregs[REG_RIP]; +} + +int arch_mcontext_arg(const mcontext_t *ctx) +{ + return ctx->gregs[REG_RDI]; +} + +static void arch_flush(void *p, int len) +{ +} + +extern char noexec_1[]; +extern char noexec_2[]; +extern char noexec_end[]; + +asm("noexec_1:\n" + " movq $1,%rdi\n" /* %rdi is 0 on entry, set 1. */ + "noexec_2:\n" + " movq $2,%rdi\n" /* %rdi is 0/1; set 2. */ + " ret\n" + "noexec_end:"); + +int main(void) +{ + struct noexec_test noexec_tests[] = { + { + .name = "fallthrough", + .test_code = noexec_1, + .test_len = noexec_end - noexec_1, + .page_ofs = noexec_1 - noexec_2, + .entry_ofs = noexec_1 - noexec_2, + .expected_si_ofs = 0, + .expected_pc_ofs = 0, + .expected_arg = 1, + }, + { + .name = "jump", + .test_code = noexec_1, + .test_len = noexec_end - noexec_1, + .page_ofs = noexec_1 - noexec_2, + .entry_ofs = 0, + .expected_si_ofs = 0, + .expected_pc_ofs = 0, + .expected_arg = 0, + }, + { + .name = "fallthrough [cross]", + .test_code = noexec_1, + .test_len = noexec_end - noexec_1, + .page_ofs = noexec_1 - noexec_2 - 2, + .entry_ofs = noexec_1 - noexec_2 - 2, + .expected_si_ofs = 0, + .expected_pc_ofs = -2, + .expected_arg = 1, + }, + { + .name = "jump [cross]", + .test_code = noexec_1, + .test_len = noexec_end - noexec_1, + .page_ofs = noexec_1 - noexec_2 - 2, + .entry_ofs = -2, + .expected_si_ofs = 0, + .expected_pc_ofs = -2, + .expected_arg = 0, + }, + }; + + return test_noexec(noexec_tests, + sizeof(noexec_tests) / sizeof(noexec_tests[0])); +} diff --git a/tests/tcg/x86_64/Makefile.target b/tests/tcg/x86_64/Makefile.target index 6177fd845a..861a0966f4 100644 --- a/tests/tcg/x86_64/Makefile.target +++ b/tests/tcg/x86_64/Makefile.target @@ -10,6 +10,7 @@ include $(SRC_PATH)/tests/tcg/i386/Makefile.target ifeq ($(filter %-linux-user, $(TARGET)),$(TARGET)) X86_64_TESTS += vsyscall +X86_64_TESTS += noexec TESTS=$(MULTIARCH_TESTS) $(X86_64_TESTS) test-x86_64 else TESTS=$(MULTIARCH_TESTS) @@ -23,5 +24,5 @@ test-x86_64: LDFLAGS+=-lm -lc test-x86_64: test-i386.c test-i386.h test-i386-shift.h test-i386-muldiv.h $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) -vsyscall: $(SRC_PATH)/tests/tcg/x86_64/vsyscall.c +%: $(SRC_PATH)/tests/tcg/x86_64/%.c $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) From patchwork Tue Sep 6 08:38:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602965 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4344865mae; Tue, 6 Sep 2022 02:06:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR4SRST+zY/wvjYm2dlqBDjSggwuTOTlc0sgbCUl11bG2ISG/KaKNxvyF6EpeIGh8BiTwKvb X-Received: by 2002:a05:620a:21d8:b0:6bc:2d3e:82bd with SMTP id h24-20020a05620a21d800b006bc2d3e82bdmr36592357qka.700.1662455211328; Tue, 06 Sep 2022 02:06:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662455211; cv=none; d=google.com; s=arc-20160816; b=mwn/8uv8Br0+iZgSf0ly5sGszD7XEEiMjz5dYb4SR1oR7zynrKlxI5ajxihZ7ZYsGq C7uOmssL822LHOXPeo4jyliTPrkG9YHb0rIn+Rz2YEeN2GJot67h+hE4RW9dNnsl6kUy 2SigIet+hJg1BGEUfi4TAcPDi070bRzpIRRTJz/5dO3qeN/SInRhTslbisVfVkZBYc7S dU1rGK7aG3xBUHtSDTtIZHs/jVOPdfGdMJ7D7kXOPuWIWrJG5DgQLqNzPvtHjgoW5cY+ aJN0uK3MMgxw/EKp6QbUg6lE4ZNv5+Y3IP22bJStoF7bBs4uQbU0icWLucPtxj6DfVRE CLGw== 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=Ar6YL5FF/K2Div4uruzg03ZvW0xj9yBOSm1jZPy9tok=; b=uJTsDq5F5nh/3ycIpuDYsb8jo5T4y9wzVFdzVus4RiKlFdUznTPAr8aQq5U4CAyj50 acZTuo6/7VQYCXkzaphHIbfXJuuwTPWWYlm8BIHmduwinHrDw1mSodgSrztt61tuXgLH luRbHLhJecbt/Odw2EnvKpZW7VLfyd09VtYuas75+1/nNWYQrQWj2q0zqELKr2i3cgU9 h9Ynao62qxaDZzZVKMomGLFyUtdMsW2pdha5SiNsJiOnBib07sZIxngj64S/7BIilUNo 7DPDsVHHOFmbQxKFMBL4F/pAeCpxZB3qcdOFVSXOKU1Mz2lmSMolE1JGCrDTGZyKQkWG /Ghg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wr+8fA7w; 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 j17-20020a05620a289100b006baa010749dsi7516553qkp.389.2022.09.06.02.06.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 02:06:51 -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=wr+8fA7w; 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]:40582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUXe-0002DX-DT for patch@linaro.org; Tue, 06 Sep 2022 05:06:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6W-0002y5-4u for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:44 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:39774) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6U-0005bS-8c for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:43 -0400 Received: by mail-wr1-x42c.google.com with SMTP id az27so14306880wrb.6 for ; Tue, 06 Sep 2022 01:38:41 -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=Ar6YL5FF/K2Div4uruzg03ZvW0xj9yBOSm1jZPy9tok=; b=wr+8fA7woVjc8qRZQe0R9g0J//X91kP+CdFAt1ZDwvon9u3M7J8QktEwNNIqFkDdkt GDFsZ9/FWCRGasf5FbhFD1NO46Cbbo2O99sIwBgm8KsSSKq9EzVniLiCCSf4RGcuS1Dt C+/JGg3sH71uMDcHgsPVTaE0/B04Kc0zFr713BzK4bVDsBEjOKg5vTR8sxTsbR48egYt HU9XQDjzDWlGHW1QSg3qx+npajtMBVYUbcLII5rDeP6bhk3JQTRvOafzT1sXa7TMIqct 09Nx34Ud+7uEG/8hPt9IYUZ084iDuCq6n+jbtjdlErq5uGlahqlCcb9sDzrXe9/I6O6y SX0w== 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=Ar6YL5FF/K2Div4uruzg03ZvW0xj9yBOSm1jZPy9tok=; b=HFwuCMr7ry0FCSFHGzbLVv1labNbPC6tWPgN3vxuIYUPbRgR6AdrWteHRKcMIVhyiT aKYeW+fPywqIQ9xZ1W1mv+QylBmay5aHIhGeJ9PHKgC9aIedVYsCWM6yCseSYrCgiRTR Xtp5WaJai5a5Ku9SselR6oOxb4U7k3DRRmFWne/zkGKFpj5DAIsNJN67+mduBB+dkUe8 N9TukMEAqBLdgbEq0ZgrFr4Z062wYKsPAv9JRxl/QGoxF18bRF31vBtVsspJOXOfviaT gNmhY75Ub3N3zHLttYUyDfRQoaVhue+ou0dIYvYVcHfRJov3okmuZ0zsUVZpFCCpdDhO GHcA== X-Gm-Message-State: ACgBeo0kvqm/aNgERygsy2knUvDRIDh4uGVfdBReYx6FAgUYtUQN0S/Z zU5UAvWuTc2Trulyly43Y/4iYc854lx3Ee84 X-Received: by 2002:a05:6000:168d:b0:226:da6a:6d78 with SMTP id y13-20020a056000168d00b00226da6a6d78mr22379665wrd.180.1662453520644; Tue, 06 Sep 2022 01:38:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Alistair Francis , Ilya Leoshkevich Subject: [PULL v3 19/20] target/riscv: Add MAX_INSN_LEN and insn_len Date: Tue, 6 Sep 2022 09:38:14 +0100 Message-Id: <20220906083815.252478-20-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::42c; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42c.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" These will be useful in properly ending the TB. Reviewed-by: Alistair Francis Acked-by: Ilya Leoshkevich Tested-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- target/riscv/translate.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/target/riscv/translate.c b/target/riscv/translate.c index 38666ddc91..a719aa6e63 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1022,6 +1022,14 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc) /* Include decoders for factored-out extensions */ #include "decode-XVentanaCondOps.c.inc" +/* The specification allows for longer insns, but not supported by qemu. */ +#define MAX_INSN_LEN 4 + +static inline int insn_len(uint16_t first_word) +{ + return (first_word & 3) == 3 ? 4 : 2; +} + static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) { /* @@ -1037,7 +1045,7 @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) }; /* Check for compressed insn */ - if (extract16(opcode, 0, 2) != 3) { + if (insn_len(opcode) == 2) { if (!has_ext(ctx, RVC)) { gen_exception_illegal(ctx); } else { From patchwork Tue Sep 6 08:38:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602968 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4350988mae; Tue, 6 Sep 2022 02:17:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR67hyx5Bih/OcnqeY9jzT7M93Zo7xQDXPEHZk4oJUMtZ1BchXiBn5j6WaI9+DXNOHhyiEUz X-Received: by 2002:a05:622a:52:b0:344:7021:dafa with SMTP id y18-20020a05622a005200b003447021dafamr41660656qtw.52.1662455833595; Tue, 06 Sep 2022 02:17:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662455833; cv=none; d=google.com; s=arc-20160816; b=lK1Aia6ckHrBA7JRHecd9XuUI2MTXvHUMha/Y5q/uEK9c6sHh1XwNqropQ9T8V0ht0 Mnb56NWJQshNhMhhCAHjOrw9/1PSduNvqVIPiocODdHtUB5pZCIH12bneZNAk4b2ViJh bVmuXAGglE2QAAe9oTevfc9B/lrRTtO1J+hXDLT+XEy93RZ1ZlDNVjn8r7kyTnxmHn0z md7AQXNx0DOQzRHg6tsi9V6LR6p6fZW2soP8EGl80Z/iKDX6udYcXviNpAzG8/5EStqv DSmTgsHgyQVQZZCndAo0hevyUUvAdkN4M2E+Lmw5+t1Cca/Yd8vy/Xp+8rYwlRT4adyr sfNA== 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=duBeBoFX8QNETCcok0dytuQZN74JHxnbRDKrjktEj6Y=; b=c/vVgmFznXdunMCOkrsDZR4PHIBhoZtG9LFRGObtWWYM/PHdnRGl88O3zvplV+z25l kdZae7AWlW6uq2c9a3pTEZRFlYgh1O7Hsk+0vpkgnJBX0tnmaxJUIPQhHjmdtPKx+gKN 7BcHG/fZPF/UdxMo3p493WcBcsJLhbpt1nIObW7uggZGVtyfRLVUSTiNCB5oXg7APJk0 aAffM0JI0zv4JPqNX79ugufAv4xmN1CuGvSB8SltUVMZTmwAEU3UL3/Bg9Fa5mmW/bVN d7nXRLoxvsMSRZat+9pjUoXdjLjfdHh59k5jx7LCrHFognnv9Oj3XqUMumi7PVafGyFJ AdDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JWUP9Lsw; 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 de15-20020a05620a370f00b006c85e42e05csi3032188qkb.714.2022.09.06.02.17.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 02:17:13 -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=JWUP9Lsw; 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]:46826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUhl-0001Py-0w for patch@linaro.org; Tue, 06 Sep 2022 05:17:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVU6W-0002zE-O2 for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:44 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:36854) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVU6U-0005UN-P2 for qemu-devel@nongnu.org; Tue, 06 Sep 2022 04:38:44 -0400 Received: by mail-wr1-x434.google.com with SMTP id b17so959375wrq.3 for ; Tue, 06 Sep 2022 01:38:42 -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=duBeBoFX8QNETCcok0dytuQZN74JHxnbRDKrjktEj6Y=; b=JWUP9Lswc0H4z0BN3y8CybqoJ/xAvUgPwNlFefR3R6UkfdmK2GBasCz+u+Vz4NePgY 0RMDJ4GrmQouMphyfoiDr+6Z/cNw9OGCHWo31oSYcvEcH47KMH7JXopASY9j5L+40n0P dQJizfvK7SjcKs1eQk59L7MYn9Cw5xMmgA1GAWIztnes9Ad23LmDz2hBTPJZawEXAhxU Mo/XNoK1y7nlYum5c4+CkLapVpLGHR0ftKH3ZesJbEGycgpg8vk7Cowf0HWv6ECZrbLG TpwKm4lbbSfHOBRC0LYS030UTHKfcf+vR8WZQuINAQiLJQlR5JYIYHJqTlMF5N6KJMIl mS7w== 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=duBeBoFX8QNETCcok0dytuQZN74JHxnbRDKrjktEj6Y=; b=735/ShRvDrvT/3c2NNcJdQddojs6t4Xefh6jAhfgI2WiBtf5O2UvNYJCMykOxRyJxG ooGDYyh6Z8lFU439lcrZR+FTdm9puBKFkP5fhAqN6KYDCrc6XrPYXxDU9HxVetE+F9Aa LWIgmSRetUtqPxlvATjv8SlHN0IsRF+zKbWTxoUoIzftLwBHmjQlQOXArPmxd8Ywncyq oXo7RDv05rAwZz+hmBOg3bmUI4GG9DyjOd0FmQc1X7PGsXh3AeSNMHM5sSUL5+5/JsrI /LXnnjcVS8fR1aEif4lUEhaXKylXC0ho+X6UXkpJFbKOS3syAJhWjJA+Wn7TwFFT/B3b TUjA== X-Gm-Message-State: ACgBeo3SEfG8EalBosgAFxBOWSq9MXt3Pl/8tijgZECtHPRhVfTts35G vBx7T4w3m09rdCm9qcMNjrbQ2SPCauB30/TC X-Received: by 2002:a5d:48d1:0:b0:225:3ee8:e5b8 with SMTP id p17-20020a5d48d1000000b002253ee8e5b8mr25183711wrs.105.1662453521952; Tue, 06 Sep 2022 01:38:41 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 01:38:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: stefanha@gmail.com, Alistair Francis , Ilya Leoshkevich Subject: [PULL v3 20/20] target/riscv: Make translator stop before the end of a page Date: Tue, 6 Sep 2022 09:38:15 +0100 Message-Id: <20220906083815.252478-21-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::434; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x434.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" Right now the translator stops right *after* the end of a page, which breaks reporting of fault locations when the last instruction of a multi-insn translation block crosses a page boundary. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1155 Reviewed-by: Alistair Francis Acked-by: Ilya Leoshkevich Tested-by: Ilya Leoshkevich Signed-off-by: Richard Henderson --- target/riscv/translate.c | 17 +++++-- tests/tcg/riscv64/noexec.c | 79 +++++++++++++++++++++++++++++++ tests/tcg/riscv64/Makefile.target | 1 + 3 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 tests/tcg/riscv64/noexec.c diff --git a/target/riscv/translate.c b/target/riscv/translate.c index a719aa6e63..f8af6daa70 100644 --- a/target/riscv/translate.c +++ b/target/riscv/translate.c @@ -1154,12 +1154,21 @@ static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) } ctx->nftemp = 0; + /* Only the first insn within a TB is allowed to cross a page boundary. */ if (ctx->base.is_jmp == DISAS_NEXT) { - target_ulong page_start; - - page_start = ctx->base.pc_first & TARGET_PAGE_MASK; - if (ctx->base.pc_next - page_start >= TARGET_PAGE_SIZE) { + if (!is_same_page(&ctx->base, ctx->base.pc_next)) { ctx->base.is_jmp = DISAS_TOO_MANY; + } else { + unsigned page_ofs = ctx->base.pc_next & ~TARGET_PAGE_MASK; + + if (page_ofs > TARGET_PAGE_SIZE - MAX_INSN_LEN) { + uint16_t next_insn = cpu_lduw_code(env, ctx->base.pc_next); + int len = insn_len(next_insn); + + if (!is_same_page(&ctx->base, ctx->base.pc_next + len)) { + ctx->base.is_jmp = DISAS_TOO_MANY; + } + } } } } diff --git a/tests/tcg/riscv64/noexec.c b/tests/tcg/riscv64/noexec.c new file mode 100644 index 0000000000..86f64b28db --- /dev/null +++ b/tests/tcg/riscv64/noexec.c @@ -0,0 +1,79 @@ +#include "../multiarch/noexec.c.inc" + +static void *arch_mcontext_pc(const mcontext_t *ctx) +{ + return (void *)ctx->__gregs[REG_PC]; +} + +static int arch_mcontext_arg(const mcontext_t *ctx) +{ + return ctx->__gregs[REG_A0]; +} + +static void arch_flush(void *p, int len) +{ + __builtin___clear_cache(p, p + len); +} + +extern char noexec_1[]; +extern char noexec_2[]; +extern char noexec_end[]; + +asm(".option push\n" + ".option norvc\n" + "noexec_1:\n" + " li a0,1\n" /* a0 is 0 on entry, set 1. */ + "noexec_2:\n" + " li a0,2\n" /* a0 is 0/1; set 2. */ + " ret\n" + "noexec_end:\n" + ".option pop"); + +int main(void) +{ + struct noexec_test noexec_tests[] = { + { + .name = "fallthrough", + .test_code = noexec_1, + .test_len = noexec_end - noexec_1, + .page_ofs = noexec_1 - noexec_2, + .entry_ofs = noexec_1 - noexec_2, + .expected_si_ofs = 0, + .expected_pc_ofs = 0, + .expected_arg = 1, + }, + { + .name = "jump", + .test_code = noexec_1, + .test_len = noexec_end - noexec_1, + .page_ofs = noexec_1 - noexec_2, + .entry_ofs = 0, + .expected_si_ofs = 0, + .expected_pc_ofs = 0, + .expected_arg = 0, + }, + { + .name = "fallthrough [cross]", + .test_code = noexec_1, + .test_len = noexec_end - noexec_1, + .page_ofs = noexec_1 - noexec_2 - 2, + .entry_ofs = noexec_1 - noexec_2 - 2, + .expected_si_ofs = 0, + .expected_pc_ofs = -2, + .expected_arg = 1, + }, + { + .name = "jump [cross]", + .test_code = noexec_1, + .test_len = noexec_end - noexec_1, + .page_ofs = noexec_1 - noexec_2 - 2, + .entry_ofs = -2, + .expected_si_ofs = 0, + .expected_pc_ofs = -2, + .expected_arg = 0, + }, + }; + + return test_noexec(noexec_tests, + sizeof(noexec_tests) / sizeof(noexec_tests[0])); +} diff --git a/tests/tcg/riscv64/Makefile.target b/tests/tcg/riscv64/Makefile.target index d41bf6d60d..b5b89dfb0e 100644 --- a/tests/tcg/riscv64/Makefile.target +++ b/tests/tcg/riscv64/Makefile.target @@ -3,3 +3,4 @@ VPATH += $(SRC_PATH)/tests/tcg/riscv64 TESTS += test-div +TESTS += noexec