From patchwork Tue Aug 16 20:33:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 597522 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp2709338maz; Tue, 16 Aug 2022 14:03:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR6X9wEC639yN4G41N1yRlAYjUiNmn9T5VnxGtc6r1lNn0aYKtM0rTJrvP7VKJbNBIO19mH/ X-Received: by 2002:ac8:5793:0:b0:342:ea28:742f with SMTP id v19-20020ac85793000000b00342ea28742fmr19994138qta.177.1660683821967; Tue, 16 Aug 2022 14:03:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660683821; cv=none; d=google.com; s=arc-20160816; b=lHTP+wx7/acPz6GH4Y998FXVz9/PtNWSILo7bGogb3HqgAxFPJrgkfBCidAQhDsOYN HbgRAzpbVWoVXD87uSNKobuawUFtkge+ab7jinpQof1yOgv9CNRB9bbpeXkwuG4gAcrG PkHpROI/ze4/wDJ7ufA2dHPSNGPto2mAXJ60D+Pfcdr84CHtJftxBW8T4XBRVd0cWo7v t+0lcecI9QW+SIbQ8mGDjIHMS3R64P8sJ/k733uYZxwRZJYJYJmXKBIJDDjUA7/Pu7Y7 AivhBvx+lbZMNc4w8Cl7TTctaXtgHjCJ0aRCahbzmEZE7YAai/gzgRfT/XbI9y1bUoq8 ajdg== 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=xPtGK6M1TngwtnTnZLI8rBr9bzgA002Z+efjpC+i5Pw=; b=NIot8qYVKM4dw3NdFYkIvAqc+dwTqzst2RFBG29+ngbtytlSqfiCQqvjMn4BlD9eWK GowWvwOE8ZauiDGg0L+DIEwp2BLHlV5K9kLzqCkCBEvXYJVtd386WnwYuDE8IxKCWUkG LZI1q37FcylvNkUmKflHfBcjY4lUgRbag1O0xS11W/820Z65tqy+d/5ZW+J8Ks1i1qHM NSobmgfaReXiPX6jzuCK9OdGbJ/3WtMXYaMSkFVkX6L3bO59tZtpotqh7xWNlRyhQ8TH wrpqruUpxwykO/WJV+MBCaKiAcWMhmUagC+FYbd/Q7fJC3yvGJ93wVHjyTbQIzzkD1QF jZeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qQGCEfSA; 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 d4-20020a05621421c400b00496a6862c05si57622qvh.203.2022.08.16.14.03.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Aug 2022 14:03: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=qQGCEfSA; 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]:38470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oO3iv-00062L-Ac for patch@linaro.org; Tue, 16 Aug 2022 17:03:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oO3Gr-0004st-4q for qemu-devel@nongnu.org; Tue, 16 Aug 2022 16:34:41 -0400 Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b]:41592) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oO3Gl-0004Uw-2x for qemu-devel@nongnu.org; Tue, 16 Aug 2022 16:34:40 -0400 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-11c21c69347so2112869fac.8 for ; Tue, 16 Aug 2022 13:34: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; bh=xPtGK6M1TngwtnTnZLI8rBr9bzgA002Z+efjpC+i5Pw=; b=qQGCEfSA2luztTiUGltj5LI3sMJBNu5jpnl++hvLA+vRy9fXkVyCKHl1J1P6hepkrQ uBVc+XQSG/6k9LdHw2rbA9GetJb78HTGL08tqimlp0AwkGDl5q5P7nv2ndqXJdqtNYxG fG6zxOr0RDhO5ArOLvf4wMjL7ZC8KlzwiQ8tqAHPuMBLIUgs39O2iCH+ch9C1p5HbOF8 5WmeehX5RJp4Yl1HcKP5x7zrokjtJF3h1yxxbI9oS+0d/vUbiT3QfXpjt47BvryyIgcA nKRFllLoqPeX9rW0x0YUq2sDr5pX+4u2sO6i2dYA1wE3NVbKxylhufTNNNvfvZAvXd/t ZeHQ== 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=xPtGK6M1TngwtnTnZLI8rBr9bzgA002Z+efjpC+i5Pw=; b=u+RjyrLUciyChHmmVUESa9QbHfK70TGtdbF8qWeqD4iQgtfn+pqP4AIDXekhfCJmQo LUPDFpN1U96PRivFgmIvqUyZHri/q/UQmCy1CG0L4x6m1MVqw1PqhK9a5da15WDifffK p26Z27jnCkQ5ZqupJXrBfWwlnnEtGpY07gSJaJ8OuKFK8RjfDHb3Ssoj+JA+dMHyRGAw AEmlBNJYRxo8Hs9qq6cb0RkoTMDadSCEronllFpv9f2guziGWABZdLWgyrECEpmPRbzR libh5DDhOxCOecmC+IqD6v2Jj5ZacihbhesxIsjAsQl9Ic3BFkvxU+slmSmOPZMotTff XDJQ== X-Gm-Message-State: ACgBeo3yag7y1xRBfVL/Rto3WuW2xJ56QMMbv6et+E6XvhHpcouf0D8D woRmnLLC0boOp1fKLcuwDuinOF9G9uvJNg== X-Received: by 2002:a05:6870:4214:b0:10b:be93:47 with SMTP id u20-20020a056870421400b0010bbe930047mr156941oac.276.1660682070819; Tue, 16 Aug 2022 13:34:30 -0700 (PDT) Received: from stoup.. ([2605:ef80:80f6:61fa:9bc2:5095:d612:5e22]) by smtp.gmail.com with ESMTPSA id y23-20020a056870b01700b0010ef8ccde67sm2285220oae.13.2022.08.16.13.34.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 13:34:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, alex.bennee@linaro.org, iii@linux.ibm.com Subject: [PATCH v2 10/33] accel/tcg: Properly implement get_page_addr_code for user-only Date: Tue, 16 Aug 2022 15:33:37 -0500 Message-Id: <20220816203400.161187-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220816203400.161187-1-richard.henderson@linaro.org> References: <20220816203400.161187-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2001:4860:4864:20::2b; envelope-from=richard.henderson@linaro.org; helo=mail-oa1-x2b.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=unavailable 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. 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 e7e30d55b8..9f35e3b7a9 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -595,43 +595,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: @@ -688,36 +689,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 5db56bcd1e..80a3eb4f1c 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1532,11 +1532,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..a20234fb02 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, true, 0); + if (unlikely(flags)) { + return -1; + } + if (hostp) { + *hostp = g2h_untagged(addr); + } + return addr; +} + /* The softmmu versions of these helpers are in cputlb.c. */ /*