From patchwork Tue Aug 23 22:05:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 599484 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp2738404mae; Tue, 23 Aug 2022 15:09:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR66smZYCphdXiXlXws0jCp/y9hjLKodntvpTeD4cJcnmwz4r4xPFqhDhhqCXgVCQoZIEod0 X-Received: by 2002:a05:622a:24c:b0:343:7d3b:4953 with SMTP id c12-20020a05622a024c00b003437d3b4953mr21543727qtx.562.1661292576404; Tue, 23 Aug 2022 15:09:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661292576; cv=none; d=google.com; s=arc-20160816; b=VhaVZJ76t5s2SnE93DBxZxMPgnoMZHHMmTeAElk/npAk4E0m0GBXYkhU9l9txkxYFI LgpIQYCA9DWtQxUbANiCjga7QKd/S9B/c0tAWF2nKbrmKLLMjBXk3OoDdgB6bNWLCEHR 4wdTnNsI8mLjKWFpRyPyybRYMH9UbZyBORz8DkDRHbFpEQGKRFwWSbhILVYCYneY/+79 H859J+2GvxR3eeos8xmQjp8CuCyYk/uzNQuGYPtjxL0zzK/3P31IarQ2WmwtxbA3cctP EQLJ6qzYrbxohL5l2zgZTw1yYSAdyG3fhgPYCZL9M4RYRAQUHLOmSZgzSCjw0UA0KV3l bbgg== 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=0BJKKX794+u71rVuTIcDWaChSDHlbW9A5LJBctnpTGM=; b=jxMxMkaUmBdNheCMt/RnHgnanM33CLHomqZqSEa/T4j2YeFmwek1wA4YMaPrpkeUQc eAHAzZE6rAU3zngCLAaGbpWtFgm0MQUzgqyn6ECtWS1ZNfyl4cb7oJFUqghDhUtpjafH WEQA9PdDQNeNx7kcLMeJDHv+5oqdbNBGhIFfXGiD1aq33o4/XGFo+oGTKMgWO7Ln1Bze srRJwQVMV0RTnA13/pt+hpkHhwUW8xkIcYw+CNrXiNWm8IYquOOmkZhxlmnoLbhvZEA1 lpSkAVjBHK5XMA3t3xPYS4XDhbSGQqCfB2oSwoVwxu6ODUtlwWEofySzqEiIcqESesG3 9PiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ykbt7e8c; 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 t8-20020ac87388000000b003437a81b47asi6640052qtp.237.2022.08.23.15.09.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Aug 2022 15:09:36 -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=Ykbt7e8c; 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]:54036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQc5W-0005qK-W2 for patch@linaro.org; Tue, 23 Aug 2022 18:09:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQc23-0008Ur-8N for qemu-devel@nongnu.org; Tue, 23 Aug 2022 18:05:59 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:53796) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQc1z-0001Qf-PE for qemu-devel@nongnu.org; Tue, 23 Aug 2022 18:05:58 -0400 Received: by mail-pj1-x102e.google.com with SMTP id m15so7195613pjj.3 for ; Tue, 23 Aug 2022 15:05:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=0BJKKX794+u71rVuTIcDWaChSDHlbW9A5LJBctnpTGM=; b=Ykbt7e8cHY80y0kCc8EqMB7111RllaIrbpg0dNgode//zbQ1le0cX+MTGBoKLd4CGG jFYVCiQpDGu1Kp8HKfXgU+YyQ+sHZVHY/ruOMnU8OQD6T0PE8JrbyhtL5uGVTr0GJfj4 G2xx3DWoG/UB77CyGczv+Jc2XwHEet3ZSSbkoVF6XD86zg4zcrUJGdrYwHKHVZ4TXmxW uV+zr0UcosHphxHcoi5CFdNjFfnErsXe09UNLT0cDT0w5zcvRvnBra5dbxJiocoMKfzD KTdUZ/Noe7DPK9+cZXN+JZb8td0MYLMuemCiSeK30W7ieYiV3Kok0+g3XIivU0+/0etY h5Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=0BJKKX794+u71rVuTIcDWaChSDHlbW9A5LJBctnpTGM=; b=gn8DtjFBRCtaMrPC8PFN+I6BqJvumaswKfbn2h2ffRAMmXPxrtxbL8pn1gLKAG9ir4 E4zIJjfPU3PvVT3zAmrtjFBhmMW8diWb/FGN8rzwMukP6N8vf6BpbzbbtUWJG8nKH62Z THHXsnSyNjkvuy1NcwqpkOgjlKpysEvvlPIGpflE60Hw0odkZg5Vj1pLpc37X7laHANj OgOXNCj7ES6myJRvhYYoqMI0yR+yo5c1Nq7rDOZp9zWB+VxeJStw/ArnRXVhfDefd7ZW LPgG7VvjbYIC6jioOZVa8I3Hrd7EmO5t7rJJXPzNJPDjCS9DR4ljemblPFLhc3I0yFRF To+w== X-Gm-Message-State: ACgBeo1p7oMPXvmZTJ9/MlppfDf6KeesX0RwNZhdPeS/eebK2QZcsF5j qZ4rKO/xj9NNKPCij91sDJPe0FFbq+5cHw== X-Received: by 2002:a17:90a:19d:b0:1f7:2b1a:947a with SMTP id 29-20020a17090a019d00b001f72b1a947amr5298230pjc.118.1661292354175; Tue, 23 Aug 2022 15:05:54 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:46f9:77b4:ec0a:c2d9]) by smtp.gmail.com with ESMTPSA id n12-20020a170902f60c00b0017292073839sm11020974plg.178.2022.08.23.15.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 15:05:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: iii@linux.ibm.com, laurent@vivier.eu, alex.bennee@linaro.org, Alistair Francis Subject: [PATCH v7 08/20] accel/tcg: Properly implement get_page_addr_code for user-only Date: Tue, 23 Aug 2022 15:05:30 -0700 Message-Id: <20220823220542.1993395-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220823220542.1993395-1-richard.henderson@linaro.org> References: <20220823220542.1993395-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.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 | 15 ++++++++ 3 files changed, 43 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..cd232967e6 100644 --- a/accel/tcg/user-exec.c +++ b/accel/tcg/user-exec.c @@ -199,6 +199,21 @@ 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); + if (unlikely(flags)) { + return -1; + } + if (hostp) { + *hostp = g2h_untagged(addr); + } + return addr; +} + /* The softmmu versions of these helpers are in cputlb.c. */ /*