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. */ /*