From patchwork Thu Sep 1 06:51: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: 601800 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp255128mae; Thu, 1 Sep 2022 00:12:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR7qXOtblv/B7+YsWoNJm9tmf60Cw/jPbL2W5a1JCnVjaKbKjdb5LwezJwBBlKEkHkLvE1x2 X-Received: by 2002:ac8:5f09:0:b0:343:67b3:96f5 with SMTP id x9-20020ac85f09000000b0034367b396f5mr22510506qta.470.1662016366631; Thu, 01 Sep 2022 00:12:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662016366; cv=none; d=google.com; s=arc-20160816; b=sjEReYkE48lw7QsBZUboS6exXIl42McB8vxmSeD46LWAOqaOcuyzdRUW4NXGbKJNuK CYERDgnh2KRZJQ5pPq1Act0CwWGTPVhxrVSDA9sM29PpXwhxwGFwccO7raXyJxYVXR7F F95b3Ti5/WLtYGnY7hhcsuFwtVmkQgLL3u7SrWs8xwMZ7XKOl0vqoVpBGTen6oZRJkSG 6oLdYEU6E6B8c6hHDHS5ZrBeT3MUfXyObWj1nlWzyoNQ/xgzY1j3IDMWP2WM35w62D5v 9yXFJzwZWnSONym7kjDvhbwApllC3lq8ioOR0rtyNwjoplpt0OuGNiCgU9e0K8VHG++9 p8+g== 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=qKbLYF+e86nVmll//KOmo5iMxBcmzrj977wU2KwzSjpkxfK7dOTACpd0v6O4DaIuii nEFt5BzuLLljjMPOofqWWk3tilnlCF1zZCC4jY06cdsWNZtXbmFzrBdJsJUyLuW9FWmh Lg6bRy/60GzTsx0ksKFjT7NmvJiCfseZ7Mm378EppzPVtJAx8MRla5w8f1Eb76/S6NGa qJfV/DKZezMDgQdoPlmbzhD81sIwl1PCQVLpf99OWriFRwmWerbnScK9P9d550OqWK2q 2vUatBKDstN1gQGFKFxgtN4/1qGgM0Qqr/8eKqlaVIOneNa8otfztWiA/XQ4OGP0J4IF ipig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FHqQJ3KF; 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 u5-20020a05620a430500b006bb49f3e3a9si9179254qko.330.2022.09.01.00.12.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Sep 2022 00:12:46 -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=FHqQJ3KF; 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]:34798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oTeNa-0001Yc-30 for patch@linaro.org; Thu, 01 Sep 2022 03:12:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oTe4O-0005wW-Qr for qemu-devel@nongnu.org; Thu, 01 Sep 2022 02:53:02 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:44639) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oTe4J-0003G6-T3 for qemu-devel@nongnu.org; Thu, 01 Sep 2022 02:52:54 -0400 Received: by mail-wr1-x42e.google.com with SMTP id c7so14348646wrp.11 for ; Wed, 31 Aug 2022 23:52:49 -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=M8k7INWbeFTVJiul2ENAwHhs/2Kfd59wQP99Hj3ZwhA=; b=FHqQJ3KF+JOwafQ6KEIh6z7Kyj7ISkA2TPydJOp9I3W0rlq9DEXm/XA7FuCf2Ptdz+ Tb8K9a6TGFAdRtrLvfnnQu1zcbeZjJRoXZDFBNUuad5KfsdMDH71QYj44mxvJd3uhyZy EfCXjfg1DIsOX3e/amKDTsKAGRaMufYJaU+cfZkVKnhDsd7H4wGQVIAAhHE9xPD3M1Or E8Vldsx4GVripCsi3a4WXWF49sTWklHKE1hF4KDiOqIEitHYmsvhYxYZSo9BWikgLTTz h19pRU7R45CMwN9NOvOTDLGowYNtidQdS28U5Mziq3lWnP+gNJlsCEGKOI7zx13vnEbM p7Vg== 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=M8k7INWbeFTVJiul2ENAwHhs/2Kfd59wQP99Hj3ZwhA=; b=AwPLA2v2tPMp+Kbtj/emP5J+uPII6fEvMygMKTt6DJpiIkzAvXUIKjmcoc2s3hXWSj US/jdziEyCVlXtYas2+IBXqixeCln27dTIp5wNY8s7WDXwQTtzBx5nNJogZnld5ZYhV2 wp9p/z8w8jbrqmPmZPmZvyzjunrkOpHiUhHZQHsJCxJ4lAhKNFQho7TcqPAkH+8zROjo AWHzku8QcQ4UxUCisU+BOEXnL9yu6Hmyff2+THUzbGCf679xjNHGq4gNsIe7s8atYXHe oYFIFzDChQoCasq9BIsoKh2r2p/tjFq4LbvyqgcjsNaaccJLGYh75luTQnSzKUnhGgeR nZmg== X-Gm-Message-State: ACgBeo1JZTzjuprxkr2ziM17Q0U6kJFFNI5obWB8CfJ1F4zXq2XWHkH0 Amum5tVHKU0SOzYLDJlMFdLUMy1qnI0DFBha X-Received: by 2002:a5d:424f:0:b0:226:d206:cd6e with SMTP id s15-20020a5d424f000000b00226d206cd6emr12870542wrr.554.1662015169351; Wed, 31 Aug 2022 23:52:49 -0700 (PDT) Received: from stoup.. ([87.192.221.83]) by smtp.gmail.com with ESMTPSA id a6-20020a5d4d46000000b00226dedf1ab7sm8308153wru.76.2022.08.31.23.52.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Aug 2022 23:52:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich , Alistair Francis Subject: [PULL 08/20] accel/tcg: Properly implement get_page_addr_code for user-only Date: Thu, 1 Sep 2022 07:51:58 +0100 Message-Id: <20220901065210.117081-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220901065210.117081-1-richard.henderson@linaro.org> References: <20220901065210.117081-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-x42e.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. */ /*