From nobody Mon Sep 16 19:03:23 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1662453788; cv=none; d=zohomail.com; s=zohoarc; b=cTA41yM/pNFuiw7zqvDz2ROlRfDSG+DRT25tbDuGdTZ8NbbLzrFcjvW46/yDZj/qt3snTIXyi9nqZd4+S/JU6rUpzJVo6BrIzsG3+ZaZnov+RT+4AaSxiBSB0yc4Upz2eWpVZZsa8lbUeBK123YII4PRaeLPNIrWn8mIzK8Zan8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662453788; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=M8k7INWbeFTVJiul2ENAwHhs/2Kfd59wQP99Hj3ZwhA=; b=Cv07RFxFYr7JI9fLJCRC4556myNVMd5gAh2DFXdyJak+v+D5INqNa5HDAHsaHpjbKOnoQSY0XdC5eTzWVFx05C8Xxh1BsEbcYVANKSlVAjj7d11TIHhRdzWG2MQWXVYGcquKQsDUG9ciulAB2uNwY/cOE8xAhFGmkDlSoYHsLOY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1662453788423547.8704819880288; Tue, 6 Sep 2022 01:43:08 -0700 (PDT) Received: from localhost ([::1]:56306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVUAk-0005fT-DH for importer2@patchew.org; Tue, 06 Sep 2022 04:43:06 -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) 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) 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-Google-Smtp-Source: AA6agR7cIe0DIqzo+BfU2FDv6oXnIhggK6UvxzvCzGyFdJZ/DxhECAu1uFl/JqDcMNy+qRIFwhtIPw== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1662453789314100001 Content-Type: text/plain; charset="utf-8" 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 attr= s); #endif =20 -#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 ad= dr, + 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); } =20 -/** - * 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 c= ontent - * is kept. - */ -static inline tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, - target_ulong addr, - void **hostp) -{ - if (hostp) { - *hostp =3D g2h_untagged(addr); - } - return addr; -} +#if defined(CONFIG_USER_ONLY) +void mmap_lock(void); +void mmap_unlock(void); +bool have_mmap_lock(void); =20 /** * adjust_signal_pc: @@ -691,36 +692,6 @@ G_NORETURN void cpu_loop_exit_sigbus(CPUState *cpu, ta= rget_ulong addr, static inline void mmap_lock(void) {} static inline void mmap_unlock(void) {} =20 -/** - * 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 ad= dr, - 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); =20 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); } =20 -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 add= r, int size, return size ? g2h(env_cpu(env), addr) : NULL; } =20 +tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong ad= dr, + void **hostp) +{ + int flags; + + flags =3D probe_access_internal(env, addr, 1, MMU_INST_FETCH, false, 0= ); + g_assert(flags =3D=3D 0); + + if (hostp) { + *hostp =3D g2h_untagged(addr); + } + return addr; +} + /* The softmmu versions of these helpers are in cputlb.c. */ =20 /* --=20 2.34.1