From nobody Wed Apr 16 13:12:32 2025 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1657607779; cv=none; d=zohomail.com; s=zohoarc; b=Kjguc0ZtMjq4B9Md6PhgkgMHxUviUk5O+vAY29p+zUr01oUs4WaoPTEh+xn9ffCXwVNEu0WQSfXl/6l+qIL18+UHA80HLfrT/aeLK0isEPgU6A2LlCWOG3Im/ZiovD7XGpTOnIqJ+qXKdpg7PudmzIpuJxLTTNXLgmpDfLfEnA4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657607779; h=Content-Type: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=NKgbO3syVPPBCsmhbVDzMpoOrW9wAuvKeglhNug4je8=; b=AN+h/WHjZ4quxOZTLa/yhbh45qjLPPXj20d9y9AmATkQVwshCIol3aFpbzFhGnbr3maJCXWHqeXWtqMo/tT8FAK7FqGygncr1YL2f6dcHa0Q8pDOyFpIK6/ORFHpJAShnVTbEXzpwMQqYMaSUVc9EOhwET9/O3WdFprvmP+p468= 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+importer=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 16576077790541012.9326381183006; Mon, 11 Jul 2022 23:36:19 -0700 (PDT) Received: from localhost ([::1]:35064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB9VJ-0004rh-Fe for importer@patchew.org; Tue, 12 Jul 2022 02:36:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB9G9-00044L-4Q for qemu-devel@nongnu.org; Tue, 12 Jul 2022 02:20:37 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]:38569) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oB9G7-0002Iw-Dx for qemu-devel@nongnu.org; Tue, 12 Jul 2022 02:20:36 -0400 Received: by mail-pg1-x52b.google.com with SMTP id e132so6706336pgc.5 for ; Mon, 11 Jul 2022 23:20:35 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id f2-20020aa79682000000b0052ab7144de8sm6040776pfk.10.2022.07.11.23.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 23:20:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NKgbO3syVPPBCsmhbVDzMpoOrW9wAuvKeglhNug4je8=; b=ug9oUTbB+WFA4/J0VCeH2DW3Th273vTRyh52yPW+O7DQZhB6jRwQ1uRhITEEePFd9d L0UZKZvHdSGSoZLdwyWIHk8vdT85gPtkAhV1C2LJWVwGnIZCOFkYE3vCBJMU5SAP/6FD aD0kPNV7TvWw2D89w/q76d9Mj83uHvMnNFniXoOHWVBVEYs7Lda6YeQyjWkiqKSmONA9 2gNu96FBFtvmiB0aA6u4J+8UzAIU2CRp6WwI2XczfvJQybLcCc5dNKMgIN5mdNxKTp+I ztJ4Wdh+OVrrlseVRYOpyH79X/llegPCh7ekSzwrQCEA+o7JBAKtzOjBCbGVJ3QhJbYb u0sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NKgbO3syVPPBCsmhbVDzMpoOrW9wAuvKeglhNug4je8=; b=OxUaCptumk2vaZnHqSqeaFaHKPuFyMxWDD3JBcwzYacqRutcMVMgGoPK/q/kzSGV1x 2oxQURmAYYd6J3Bb9UF8qEL2wefHIKyuZQ34vtkpf7kW+EfIN39dLFJKIoBTPvHEB+8e F/Od2ZTVHOqyBpqceYc0f+E3kAxB7h0tZdbc2+msX9nuvu/M+H/Dw4EqXpVl5fkyrkRK 1W+HL9Ir67aWQITAPBZpirzDGrAmPiXBHQGN7oFHgIY/4U5MhgTeqb4glHpTMOS+NjZ3 clVbag0US7nqC8RrZVzu0G1v5nIskH0GhHcD+j2fX/AlCDFYqR+mfwQ6zWl39wz/CaX8 5vCg== X-Gm-Message-State: AJIora/F3qNc18iwy/dHiZ3cPOpZ/Ocsq3Y1iEt5pcidl1DkJFsWW2Z7 8F3uVKIbdRNkrjYqJSqN2DquQFHeRLbEJ7rT X-Google-Smtp-Source: AGRyM1uOjaTtlrnc7a9nJlXQ8N9kpQxZug9LzbPQaWLP7JIUePmHQ1PJRet+J/Oc8iGUF3yvfhKHag== X-Received: by 2002:a05:6a00:2487:b0:525:7c72:ee73 with SMTP id c7-20020a056a00248700b005257c72ee73mr21986951pfv.47.1657606833999; Mon, 11 Jul 2022 23:20:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Shaobo Song , qemu-stable@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL 1/2] tcg: Fix returned type in alloc_code_gen_buffer_splitwx_memfd() Date: Tue, 12 Jul 2022 11:50:24 +0530 Message-Id: <20220712062025.197634-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220712062025.197634-1-richard.henderson@linaro.org> References: <20220712062025.197634-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1657607780935100001 From: Shaobo Song This fixes a bug in POSIX-compliant environments. Since we had allocated a buffer named 'tcg-jit' with read-write access protections we need a int type to combine these access flags and return it, whereas we had inexplicab= ly return a bool type. It may cause an unnecessary protection change in tcg_region_init(). Cc: qemu-stable@nongnu.org Fixes: 7be9ebcf924c ("tcg: Return the map protection from alloc_code_gen_bu= ffer") Signed-off-by: Shaobo Song Reviewed-by: Alex Benn=C3=A9e Message-Id: <20220624150216.3627-1-shnusongshaobo@gmail.com> Signed-off-by: Richard Henderson --- tcg/region.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcg/region.c b/tcg/region.c index 71ea81d671..88d6bb273f 100644 --- a/tcg/region.c +++ b/tcg/region.c @@ -548,7 +548,7 @@ static int alloc_code_gen_buffer_anon(size_t size, int = prot, #ifdef CONFIG_POSIX #include "qemu/memfd.h" =20 -static bool alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) +static int alloc_code_gen_buffer_splitwx_memfd(size_t size, Error **errp) { void *buf_rw =3D NULL, *buf_rx =3D MAP_FAILED; int fd =3D -1; --=20 2.34.1 From nobody Wed Apr 16 13:12:32 2025 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1657608260; cv=none; d=zohomail.com; s=zohoarc; b=mcpD8IO26Qv8TokDw1E8gqb4F2BBtpLDpev5pfnoakBRiN5QLa3v8aZVydvVIstqAwm7TrXK4/76dJ7djMFAzSo9jXOOuSKaG3MMs2qCOzlHIIBf+I9dei2V2Ko1u3I2DjyEXmPgV08uYz/m+0LFxVxGfwey2k8NNdT7niuycXg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657608260; 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=ameaOYTaejX0n/etuEC9PIIeVKsPKESqsBuicmuydr8=; b=aqHNpVb8puLhdTvLu7Dq7iNCUhKayvWH4grA4Pi63Y5LqjGxtrMM4BKnkxAPyDREmbrN8PHW5xmX74PSL+2UITDvXLeP7w7y3SRz1qxLawlGuA42Sqrprm2zPb1gnkBkjEHkFM+OQ5KLvse9gxRyf+EOM7wPZuXzMlekVdk6CTI= 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+importer=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 1657608260827980.1969243594702; Mon, 11 Jul 2022 23:44:20 -0700 (PDT) Received: from localhost ([::1]:43450 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB9d5-0002Q5-4y for importer@patchew.org; Tue, 12 Jul 2022 02:44:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51358) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oB9GB-00047r-5K for qemu-devel@nongnu.org; Tue, 12 Jul 2022 02:20:39 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:42882) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oB9G9-0002JE-IJ for qemu-devel@nongnu.org; Tue, 12 Jul 2022 02:20:38 -0400 Received: by mail-pg1-x534.google.com with SMTP id o18so6690833pgu.9 for ; Mon, 11 Jul 2022 23:20:37 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id f2-20020aa79682000000b0052ab7144de8sm6040776pfk.10.2022.07.11.23.20.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 23:20:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ameaOYTaejX0n/etuEC9PIIeVKsPKESqsBuicmuydr8=; b=IsMnhkWb90qtkcnR29Z/AMLQKysLRdZ3FIyeDsjqFW37OOifRNF641/vb5NgzWIs5e xFuiG/QXsB2kvb89tpE1rMioARlyhjNeQlg9XF8KU055JDjrG8crVBpn2FN81CosOUQD qQNqWTZNkpomCV8CE1+xf9lW3hgy5o0DUkTosLx8JAoEJPnfWCxCa2LXMkSwJ4FkhrdH brr8Y/7SjZqIJoYECB+Qbvt/b6xRZiNUmakVFAl6wKEnUdQ+3NSeQwwnCk4k7+V9HQ3B 6dGj24uJNHr0zJYgGSRESnvZN3Ibm0zXMT6qeGNkBhXo4WBKByHFIlYRkwZQTlNYX5qd Y6gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ameaOYTaejX0n/etuEC9PIIeVKsPKESqsBuicmuydr8=; b=yc2rBA9Z5QdPrSM0Y0bTbj/088Lx9nnacftT5jPvwgnYvA0EmRbqtdZi8gfk+Cy6qf LOfpuzXfIdXclMjrJRpPC6+fDqzKcNlkFhvKMr163S4JqGtB6TDOWAA+bxb1NRXv6Mj+ HD2OGFBvAuMEW+tdFhGXUv+BMSSY/emvdJISy4i8KNInj9e1zyyUJ1UJcKDaRWMag/JA i4lOkYGNwyRWIiDxcQXi9cA3S642HRNwUlVppJ+YK9lWz3xbTSl2CEDEL0LKktWy2mE8 vobYFRuVz/1v7aS0UtqRtrpGwm4U2YTA3W7bmwrZ29wRhKNFsRl4xxRfUYTdFr79wM/Q fYug== X-Gm-Message-State: AJIora/hHbPGTQ3t4jCRTLhg+7AwHtfck5PUBpg8Qxqsz8xaOMKh21b1 cyKmZ7qrqWR6DcsDzBNQHG7Pyxji53w07zr0 X-Google-Smtp-Source: AGRyM1sXGSEKbRAfIteRspOMlwXjZ5JaXAwDpJPyp7dCC4cBmEWskTfWtqVp/CnkVpxQlaTb82q2Iw== X-Received: by 2002:a63:c15:0:b0:411:f92a:8ec7 with SMTP id b21-20020a630c15000000b00411f92a8ec7mr18895806pgl.86.1657606836196; Mon, 11 Jul 2022 23:20:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Ilya Leoshkevich Subject: [PULL 2/2] accel/tcg: Fix unaligned stores to s390x low-address-protected lowcore Date: Tue, 12 Jul 2022 11:50:25 +0530 Message-Id: <20220712062025.197634-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220712062025.197634-1-richard.henderson@linaro.org> References: <20220712062025.197634-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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x534.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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1657608262366100001 Content-Type: text/plain; charset="utf-8" From: Ilya Leoshkevich If low-address-protection is active, unaligned stores to non-protected parts of lowcore lead to protection exceptions. The reason is that in such cases tlb_fill() call in store_helper_unaligned() covers [0, addr + size) range, which contains the protected portion of lowcore. This range is too large. The most straightforward fix would be to make sure we stay within the original [addr, addr + size) range. However, if an unaligned access affects a single page, we don't need to call tlb_fill() in store_helper_unaligned() at all, since it would be identical to the previous tlb_fill() call in store_helper(), and therefore a no-op. If an unaligned access covers multiple pages, this situation does not occur. Therefore simply skip TLB handling in store_helper_unaligned() if we are dealing with a single page. Fixes: 2bcf018340cb ("s390x/tcg: low-address protection support") Signed-off-by: Ilya Leoshkevich Message-Id: <20220711185640.3558813-2-iii@linux.ibm.com> Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index f90f4312ea..a46f3a654d 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -2248,7 +2248,7 @@ store_helper_unaligned(CPUArchState *env, target_ulon= g addr, uint64_t val, const size_t tlb_off =3D offsetof(CPUTLBEntry, addr_write); uintptr_t index, index2; CPUTLBEntry *entry, *entry2; - target_ulong page2, tlb_addr, tlb_addr2; + target_ulong page1, page2, tlb_addr, tlb_addr2; MemOpIdx oi; size_t size2; int i; @@ -2256,15 +2256,17 @@ store_helper_unaligned(CPUArchState *env, target_ul= ong addr, uint64_t val, /* * Ensure the second page is in the TLB. Note that the first page * is already guaranteed to be filled, and that the second page - * cannot evict the first. + * cannot evict the first. An exception to this rule is PAGE_WRITE_INV + * handling: the first page could have evicted itself. */ + page1 =3D addr & TARGET_PAGE_MASK; page2 =3D (addr + size) & TARGET_PAGE_MASK; size2 =3D (addr + size) & ~TARGET_PAGE_MASK; index2 =3D tlb_index(env, mmu_idx, page2); entry2 =3D tlb_entry(env, mmu_idx, page2); =20 tlb_addr2 =3D tlb_addr_write(entry2); - if (!tlb_hit_page(tlb_addr2, page2)) { + if (page1 !=3D page2 && !tlb_hit_page(tlb_addr2, page2)) { if (!victim_tlb_hit(env, mmu_idx, index2, tlb_off, page2)) { tlb_fill(env_cpu(env), page2, size2, MMU_DATA_STORE, mmu_idx, retaddr); --=20 2.34.1