From patchwork Sat Apr 1 04:51:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 669417 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp843982wrt; Fri, 31 Mar 2023 21:52:01 -0700 (PDT) X-Google-Smtp-Source: AK7set+7Wtz0FCLZ2P1usLir4fPRT7B3Yuo2lyz5qDhJX9L5l4EDQwsvB9cgZKDkuZpq2lP6/R6e X-Received: by 2002:ac8:58d6:0:b0:3e3:7e6f:423c with SMTP id u22-20020ac858d6000000b003e37e6f423cmr51082755qta.34.1680324721301; Fri, 31 Mar 2023 21:52:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680324721; cv=none; d=google.com; s=arc-20160816; b=zAuzMHbm10dFXfa39+eBSqYqGU/SBXFSIQGvuDTUlSi96dcXzPnHs6/JEg9NlSmovt JEpFhBbtgDzYZCqYA60wrsj2aKZWx+tlCHY0McCniZbkZfDQLOPPbn+U+rIjOe2OuHdS 2mXumZsTV3BF+4PoyTptvVOeeHmBA8iUrBHXynFTrcgiugd38lQ8AaBykVXS8vxueiOa N8V7T3cpmAgQkUV1zXC+JWjrUwjgiEJC2U+X7HIO+x8Ea7d2IHnQSFXuDysjunQgdgZX 14XTmHOIorNuONq2Uc/+Ru1a711wEm5GxoKj5rajf1J9GjeyfA6Fg9sKZpTeuWLhvRPq 35oA== 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=kiULY7hI3dkf5M/9do5JIhSCZ7Y5eX3RA+ervNTgBK8=; b=mWCEk9Bl50j18esJYdFjnDytJ+3cSX7lREusWObZOodn7LxSNbaq/depVivLA6mVXX ZY78hUhn/VwPy7NHM5RoaIKhhWxZ13LWfcTLgLkqTuNncHxO/KJVRYtVrT9NYaQB9T+9 3V7VBHq12xgNCIbvh5xc1BZqfD3MZ1AwnIneGILOAmwzbi4RkHu8NW06OG3oNfpCYH7M lLWmmQi8URYPcfaI9msUwwIrj6qMKEhuhDmUp85Wvvs+EpDSHtYrxWOYTJh7eiHu1mJ3 mekuDRhQdPF5h9RKEsCUg7F55CsTQtST0buH4RoI8U/eOVcT3fCXPy2y3GZYbuy0v3Xp B57Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UDg0lR/0"; 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 br7-20020a05620a460700b007468cbaaefdsi2889052qkb.378.2023.03.31.21.52.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Mar 2023 21:52:01 -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="UDg0lR/0"; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1piTCw-0003rt-24; Sat, 01 Apr 2023 00:51:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1piTCr-0003qh-RZ for qemu-devel@nongnu.org; Sat, 01 Apr 2023 00:51:13 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1piTCo-0003Nz-8c for qemu-devel@nongnu.org; Sat, 01 Apr 2023 00:51:13 -0400 Received: by mail-pj1-x1032.google.com with SMTP id p13-20020a17090a284d00b0023d2e945aebso10093630pjf.0 for ; Fri, 31 Mar 2023 21:51:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680324668; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kiULY7hI3dkf5M/9do5JIhSCZ7Y5eX3RA+ervNTgBK8=; b=UDg0lR/0pRSWX6TCc3shno0pfhNggxNqN1QEDq07xnQw6ZMGtnLm/mv734ZFMtgDIN avPhobF60hxnm6SzZBWxZJetWN1ZzkcW6qbdzyHERDeNxD3IXGJ+a0glO2Xruq2p7kCC ZbV2S+ceF3WZs984DjTuByQrA5Ct0Su72tOQNkZoGmZeajPJJ6mval0KTJXhM0yyHgfa p1F7XOtdOnIGlwz9rONx3jYmZlHIi9s8ocw7nx8tKIyALxBeHjS09oD9ILwSiMDGd9HO 1tLihRcpCiNVq808H1/BQQm73EHJ1v+i2T0LMDHYRoxELogXK8YHRqkBFV8CZ92CEJTo fEtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680324668; 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:message-id:reply-to; bh=kiULY7hI3dkf5M/9do5JIhSCZ7Y5eX3RA+ervNTgBK8=; b=otlSPiaFEpRMcwyYVVgnUqa3dM10htTDANmVkb6C6L5An3DESa6JTDTfKRmcd76xl+ ovGUbc4REUYPQhABCb0a4mDwIdk1QNF7xrpihf+kygEGtCNcJI2GSXypD3RY7GP3Y3Va xdMfK7AZpcHKn/G+okBlIXVv1Z9GJL8OMa4lTxAaOaRtIy+FAyB8hUNelXwrWB4MkwDg j/BmHj9kLDcVQpO5ZSrGXY1QiyMa41L/YfpviqF/n/mASLeoEw30LfPBdmhQwbQl7YA3 ftScGaQNtsJ9vQHugt/pL7sKHIWFu6jlSAZzk2TSrQu0u3pIdRE2iyLMUYOcPB3zXAgT ypNw== X-Gm-Message-State: AAQBX9cKpU1UY577KHR4d02CMQlV63ZOm3kek5otWllMKTQhoZvUqpPB HkqkV5ebwZgP+Djv/jnwY/B1EOPCWjlmHztfNek= X-Received: by 2002:a17:903:1d1:b0:1a1:ad5e:bdbb with SMTP id e17-20020a17090301d100b001a1ad5ebdbbmr38676830plh.36.1680324668564; Fri, 31 Mar 2023 21:51:08 -0700 (PDT) Received: from stoup.. ([2602:ae:1541:f901:b714:1fce:85fa:2fc7]) by smtp.gmail.com with ESMTPSA id a17-20020a170902ee9100b001a24cded097sm2360122pld.236.2023.03.31.21.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 21:51:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org Subject: [PATCH 1/3] Revert "linux-user/arm: Take more care allocating commpage" Date: Fri, 31 Mar 2023 21:51:04 -0700 Message-Id: <20230401045106.3885562-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230401045106.3885562-1-richard.henderson@linaro.org> References: <20230401045106.3885562-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.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 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-bounces+patch=linaro.org@nongnu.org This reverts commit 4f5c67f8df7f26e559509c68c45e652709edd23f. This exposes bugs in target_mmap et al with respect to overflow with the final page of the guest address space. To be fixed in the next development cycle. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- linux-user/elfload.c | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/linux-user/elfload.c b/linux-user/elfload.c index b96b3e566b..f1370a7a8b 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -423,32 +423,12 @@ enum { static bool init_guest_commpage(void) { - ARMCPU *cpu = ARM_CPU(thread_cpu); - abi_ptr want = HI_COMMPAGE & TARGET_PAGE_MASK; - abi_ptr addr; + abi_ptr commpage = HI_COMMPAGE & -qemu_host_page_size; + void *want = g2h_untagged(commpage); + void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); - /* - * M-profile allocates maximum of 2GB address space, so can never - * allocate the commpage. Skip it. - */ - if (arm_feature(&cpu->env, ARM_FEATURE_M)) { - return true; - } - - /* - * If reserved_va does not cover the commpage, we get an assert - * in page_set_flags. Produce an intelligent error instead. - */ - if (reserved_va != 0 && want + TARGET_PAGE_SIZE - 1 > reserved_va) { - error_report("Allocating guest commpage: -R 0x%" PRIx64 " too small", - (uint64_t)reserved_va + 1); - exit(EXIT_FAILURE); - } - - addr = target_mmap(want, TARGET_PAGE_SIZE, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); - - if (addr == -1) { + if (addr == MAP_FAILED) { perror("Allocating guest commpage"); exit(EXIT_FAILURE); } @@ -457,12 +437,15 @@ static bool init_guest_commpage(void) } /* Set kernel helper versions; rest of page is 0. */ - put_user_u32(5, 0xffff0ffcu); + __put_user(5, (uint32_t *)g2h_untagged(0xffff0ffcu)); - if (target_mprotect(addr, qemu_host_page_size, PROT_READ | PROT_EXEC)) { + if (mprotect(addr, qemu_host_page_size, PROT_READ)) { perror("Protecting guest commpage"); exit(EXIT_FAILURE); } + + page_set_flags(commpage, commpage | ~qemu_host_page_mask, + PAGE_READ | PAGE_EXEC | PAGE_VALID); return true; } From patchwork Sat Apr 1 04:51:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 669418 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp844028wrt; Fri, 31 Mar 2023 21:52:15 -0700 (PDT) X-Google-Smtp-Source: AKy350ZN1FCpxQ3XwtgKI8YG7mOmI81ua2Z1+JzYaPEWaHBp2P91BIpbt1tVVRdbfxTyBy9B6gy9 X-Received: by 2002:a05:6214:246a:b0:5ab:c25f:9791 with SMTP id im10-20020a056214246a00b005abc25f9791mr51008902qvb.29.1680324735498; Fri, 31 Mar 2023 21:52:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680324735; cv=none; d=google.com; s=arc-20160816; b=YSROxxpBMdkJ9JwOKZpErOuDnKjajsvmWis2rrTDq6JIOzSK9Q4gcKlo7yXJ6/X4qU rui5fOWPajLehkpLdK7/N+1A4fUBAei/uhP+kBwOY1FnBqPOPNK3Y/4FAokWjIqPN7TA mLO7LcXsaQIrz/CbdOgEw9RMGvNWnM7ebqeS4T1mJb557sVxPqa+aWEksRu9av/eG0Yk OOBN1cvsYJcwF4Cmr7JxyBzHO1i+sfyWcU7bzhUsBGLCBVKm96ZHZ73NCt3UqZOAQOd/ miFIn2mgY/F3iWOUV6vIjZdJwWCF1/wZTrIYnrOUIizAoaXFKdMBAmbcL2djSDdTg4N6 YeEA== 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=EH536+i2nk5iE4kCFR7uLvByCyKiD9xDAloG6x5h4Xs=; b=eaFBEJX8TAdVpBoRNdQruQU1g1/tv22nNOJVpzjIK09iR6sR/TFb57IZvv6LzuWwaM sXCTbmTl4N3x7jsJokMywD5W7vJJrFeNUvSuM9Hxb8hk8aMcd9xFDGDJZ469mfr2wew6 29ydfLMBXeUX7+dgg4/mzmWSzQRo9QMbXLwH+7xpHNZPapp8sIqxyWXwYOEWKyiQ31FM U01oESPa51hS5Uhb13HMnjYvmc+UlmW+BJUixEgMgsSASBcdlck+1bzgN0ot9p7D3mfL eY9NgKnmosbjmKhv88VOnMjcQmKpyMeyaONt7pVgDERa751LZmB3Mns0X7v1pxd6BWzp xYYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XfOQwyPq; 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 s194-20020a37a9cb000000b00746556be41csi2710256qke.97.2023.03.31.21.52.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Mar 2023 21:52:15 -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=XfOQwyPq; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1piTCt-0003r9-Kw; Sat, 01 Apr 2023 00:51:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1piTCr-0003qQ-2o for qemu-devel@nongnu.org; Sat, 01 Apr 2023 00:51:13 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1piTCo-0003O7-Rh for qemu-devel@nongnu.org; Sat, 01 Apr 2023 00:51:12 -0400 Received: by mail-pj1-x1036.google.com with SMTP id h12-20020a17090aea8c00b0023d1311fab3so25608113pjz.1 for ; Fri, 31 Mar 2023 21:51:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680324669; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EH536+i2nk5iE4kCFR7uLvByCyKiD9xDAloG6x5h4Xs=; b=XfOQwyPq6UAPn29ky+taPVmxqZeIW0yAqk+0/ho5bXOKn2FtGZcPFB29VCvvvq3mm6 hFm/bIc7CIg1rEDPMEBQx/VR2NH4J2Ji8S34/ISPveNRI0Gx/Zd57qH8ePAya+79sJqD LhoMv1jKwlgq2QnK2i6w7PnV0sKt9yPyPQY13vrwizvLDmRH3boRW+me+WiWFwqGaF7/ m7SfB+Oz0ZuPVgFSs1jA4IAuC8VXpXWIGN0Onhf0xRuzbNVFt3dQOen/SgcyiH0o5zJC 309KafILezBuVt2arNfcDyUQdg5aRR17Qw5vX/EGiwwUkoVuNpD8l9sMCs0Ld1J+6o9E 8dKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680324669; 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:message-id:reply-to; bh=EH536+i2nk5iE4kCFR7uLvByCyKiD9xDAloG6x5h4Xs=; b=HgbdF4SAyJGf6RDCKscyHq2jPLn5JigZywoW77csjaJ//ekBB6Jq8DJswVHYm/JSRw iBb33EfPeEDQAmpGj4l+dts232ZuEor24HeSsS9Ok9P1EfRFs629AmeL4UADKkmw0zbS 3JBP6rcTPuCKSJzeoLKMjHqOos2ezxKGEIMQRg65QLK4RPRSVYvWApwhwaCins05MUWD nw0hvx1bW3QdFLxl4oQlwqYvvqoqj3qy4SZV+vsMAQwxHI/VNgd5jC8q9o0olZY0h64K Gv0mDH4+tiOCXXHJoKpY5P6zT6pCo8v2xMq4OVe9NTm8ToF2AxVHHZfYjkFbsU4HuxXX k80w== X-Gm-Message-State: AAQBX9c2EvsZ2XFgFR3jVq1wFE4jTUDqqKmuqqZXEnJ/FsWH6wGO9APt 5dQi7UZN+LOO89WBmtwgWnuQyBHAN9OCIi1yZ5I= X-Received: by 2002:a17:90b:3b4a:b0:23f:1868:94fa with SMTP id ot10-20020a17090b3b4a00b0023f186894famr32745919pjb.36.1680324669445; Fri, 31 Mar 2023 21:51:09 -0700 (PDT) Received: from stoup.. ([2602:ae:1541:f901:b714:1fce:85fa:2fc7]) by smtp.gmail.com with ESMTPSA id a17-20020a170902ee9100b001a24cded097sm2360122pld.236.2023.03.31.21.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 21:51:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, Weiwei Li , Junqiang Wang Subject: [PATCH 2/3] accel/tcg: Fix overwrite problems of tcg_cflags Date: Fri, 31 Mar 2023 21:51:05 -0700 Message-Id: <20230401045106.3885562-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230401045106.3885562-1-richard.henderson@linaro.org> References: <20230401045106.3885562-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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 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-bounces+patch=linaro.org@nongnu.org From: Weiwei Li CPUs often set CF_PCREL in tcg_cflags before qemu_init_vcpu(), in which tcg_cflags will be overwrited by tcg_cpu_init_cflags(). Fixes: 4be790263ffc ("accel/tcg: Replace `TARGET_TB_PCREL` with `CF_PCREL`") Reviewed-by: Richard Henderson Signed-off-by: Weiwei Li Signed-off-by: Junqiang Wang Message-Id: <20230331150609.114401-6-liweiwei@iscas.ac.cn> Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- accel/tcg/tcg-accel-ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accel/tcg/tcg-accel-ops.c b/accel/tcg/tcg-accel-ops.c index af35e0d092..58c8e64096 100644 --- a/accel/tcg/tcg-accel-ops.c +++ b/accel/tcg/tcg-accel-ops.c @@ -59,7 +59,7 @@ void tcg_cpu_init_cflags(CPUState *cpu, bool parallel) cflags |= parallel ? CF_PARALLEL : 0; cflags |= icount_enabled() ? CF_USE_ICOUNT : 0; - cpu->tcg_cflags = cflags; + cpu->tcg_cflags |= cflags; } void tcg_cpus_destroy(CPUState *cpu) From patchwork Sat Apr 1 04:51:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 669419 Delivered-To: patch@linaro.org Received: by 2002:a5d:4d08:0:0:0:0:0 with SMTP id z8csp844044wrt; Fri, 31 Mar 2023 21:52:18 -0700 (PDT) X-Google-Smtp-Source: AKy350bkeN5esTsRCA7p2dZCvr2vVZNxxXO2Obt0KtoApXb+ijxmvSEGyTkY59Wa2qMGgSb9ok8m X-Received: by 2002:a05:6214:48e:b0:56f:8b5:3e94 with SMTP id pt14-20020a056214048e00b0056f08b53e94mr21848475qvb.14.1680324738586; Fri, 31 Mar 2023 21:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680324738; cv=none; d=google.com; s=arc-20160816; b=uW8/NQXevhxfqAcfjvkXF4i4FlnzqRe6Wxgxw5Wobv4++lhxBdP2H3QzB0K1gK+3+6 KLmMYhUBRlqwTdS6Xqvj1z2MQLMkfAh0PH/83cSz64OUKTEDgQlI2tz/bpnGatp93M0B EgrD1S7ejoOP2uVpDC3bMZW/BH+/03k8+ALpzMEKSBGCixcqYPWw74AMD03KwHz35e77 8BccFtDSpelstJY7K4zoM0ggu39/XKVOgJys1TnOwdzmDhOxIx9H4SSaxi1pcffvDJ6G lVH5bStltdTYaKLTdEABRK1oxJGkJbGbNk11kLhYWP55jgAKOiMzUgZvFPQUeLKONAy5 RssA== 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=5bGxmCesttnNxUtKHDP3pWQs68ofrrfygUflIUG0Pek=; b=RUkaniL+c0g6dn0ckFqJ2/7dsLM+cIPHgpJ4p0lR9zGhqZFYB/Tzzmm0LWFp/CfkdY MHdVW9iOrxBHfOfYmeViQPe+md4JFlG9lQ/r5Nj+HE1kfta4NZJSx0thqOGqR5/4+koZ P0p2ZRN8q3X/RDFtPgGNJt9CmQLiI4Av32UatJIZ71qEVvtbJUHcp+4nBMAE0942nD9z IbLlXeOxTamNF3YtcdjrL03UkFH5Nrhx52vtgi7XHHsKgytbUm9F2tFWj0tr2yPqcTIC s0uJiwtwPU5hBjF++76Xm1PgTEH6dOUOxDzSl+Es5fxdCHnbcotvZ6QoiW4Eod2Z2swJ U7+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="t/izS8NM"; 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 f1-20020a05622a1a0100b003e4e07e4c69si2651185qtb.775.2023.03.31.21.52.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Mar 2023 21:52:18 -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="t/izS8NM"; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1piTCs-0003r4-TU; Sat, 01 Apr 2023 00:51:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1piTCr-0003qY-E1 for qemu-devel@nongnu.org; Sat, 01 Apr 2023 00:51:13 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1piTCp-0003PJ-L2 for qemu-devel@nongnu.org; Sat, 01 Apr 2023 00:51:13 -0400 Received: by mail-pl1-x636.google.com with SMTP id u10so23318833plz.7 for ; Fri, 31 Mar 2023 21:51:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680324670; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5bGxmCesttnNxUtKHDP3pWQs68ofrrfygUflIUG0Pek=; b=t/izS8NMP7K+fItsIFZdOqlV+fhWYjouDJCX21+WtsH8jm1BAjOvd9xLUaU908Ktq6 xtx1RShsy5Vxjz0nXL81Jc1k3qzPPotq4gNwn2/WZD7Twl5xv2ss3+4dwrBRDjjX7pkG uFTDLuaPU8n9A+2MT08cxsdC928n+eGWFnkSJXG6QgYNBXnDMxzhnW16AK+RRJ+CVIJD M3qLZXalnzfWoboYVRJBRwkgiX6z0FVQxuRhBd5P0w++2CJdTofcOZr31Q18z9EWH2yp CoJ267vkVpIdEPFIwf2/iFwP8ycHAaAAFx1y9lj9bJwPFWKUhyNsRZIQXzU/7DWDeRDq OoEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680324670; 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:message-id:reply-to; bh=5bGxmCesttnNxUtKHDP3pWQs68ofrrfygUflIUG0Pek=; b=BtRlHDLV5mV9jo1msP4Camto/JgAr4j/qdLYFgeGek2Y3+N/75JSJgbCLVXJfn7h+/ BAFpy68aEAg3JvMCFt9l2vyDWDYYqHsgPYxIMhiWnr94BTim5xf9UEmqK4xgNLlbgyZs F8C8N8JEN3nqOPSBzLkvnAynCPCNSMT64nNaE1/SmeW1J4PCLPH+YD7PI4e3VHvqBIB8 6mxL/9CRbEqVVn2qQ8LvPYgt0r0srG44mwL3K9l1CPxNKPJS1LMPGVE30a/lG8FRNzTD H/u510dTxaHWGKfxCCFPEv1qFKUMYezbg9192f1AquW3Jj3BF0/A5g7mreZ1rF1H4WOM IcAQ== X-Gm-Message-State: AAQBX9dN42NHFb4EahbdHlar3Wr95jQtZ57IE92cJgwgUGBYBcbEQG7s EzzjqOEmVUW0DmCJDv/43v9k5dGHvZlx2ZxdWsQ= X-Received: by 2002:a17:903:2290:b0:1a1:a727:a802 with SMTP id b16-20020a170903229000b001a1a727a802mr13180560plh.19.1680324670262; Fri, 31 Mar 2023 21:51:10 -0700 (PDT) Received: from stoup.. ([2602:ae:1541:f901:b714:1fce:85fa:2fc7]) by smtp.gmail.com with ESMTPSA id a17-20020a170902ee9100b001a24cded097sm2360122pld.236.2023.03.31.21.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 21:51:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, Weiwei Li Subject: [PATCH 3/3] accel/tcg: Fix jump cache set in cpu_exec_loop Date: Fri, 31 Mar 2023 21:51:06 -0700 Message-Id: <20230401045106.3885562-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230401045106.3885562-1-richard.henderson@linaro.org> References: <20230401045106.3885562-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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 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-bounces+patch=linaro.org@nongnu.org Assign pc and use store_release to assign tb. Fixes: 2dd5b7a1b91 ("accel/tcg: Move jmp-cache `CF_PCREL` checks to caller") Reported-by: Weiwei Li Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- accel/tcg/cpu-exec.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index c815f2dbfd..8370c92c05 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -257,7 +257,7 @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc, if (cflags & CF_PCREL) { /* Use acquire to ensure current load of pc from jc. */ - tb = qatomic_load_acquire(&jc->array[hash].tb); + tb = qatomic_load_acquire(&jc->array[hash].tb); if (likely(tb && jc->array[hash].pc == pc && @@ -272,7 +272,7 @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc, return NULL; } jc->array[hash].pc = pc; - /* Use store_release on tb to ensure pc is written first. */ + /* Ensure pc is written first. */ qatomic_store_release(&jc->array[hash].tb, tb); } else { /* Use rcu_read to ensure current load of pc from *tb. */ @@ -971,18 +971,27 @@ cpu_exec_loop(CPUState *cpu, SyncClocks *sc) tb = tb_lookup(cpu, pc, cs_base, flags, cflags); if (tb == NULL) { + CPUJumpCache *jc; uint32_t h; mmap_lock(); tb = tb_gen_code(cpu, pc, cs_base, flags, cflags); mmap_unlock(); + /* * We add the TB in the virtual pc hash table * for the fast lookup */ h = tb_jmp_cache_hash_func(pc); - /* Use the pc value already stored in tb->pc. */ - qatomic_set(&cpu->tb_jmp_cache->array[h].tb, tb); + jc = cpu->tb_jmp_cache; + if (cflags & CF_PCREL) { + jc->array[h].pc = pc; + /* Ensure pc is written first. */ + qatomic_store_release(&jc->array[h].tb, tb); + } else { + /* Use the pc value already stored in tb->pc. */ + qatomic_set(&jc->array[h].tb, tb); + } } #ifndef CONFIG_USER_ONLY