From patchwork Tue Jul 12 06:20:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 589784 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:bb16:0:0:0:0 with SMTP id jd22csp3920443mab; Mon, 11 Jul 2022 23:42:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1up6du9hUtNbKXqO7sPWX/x+/Y2qrqyrLb2XAjIzfLTXyG6yonzh5iabUpd4TxJFujj76d1 X-Received: by 2002:a05:622a:1451:b0:31d:24ee:1ad3 with SMTP id v17-20020a05622a145100b0031d24ee1ad3mr16886381qtx.215.1657608142932; Mon, 11 Jul 2022 23:42:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657608142; cv=none; d=google.com; s=arc-20160816; b=cpapD5Xeg625S+pFA+l0ivwhLRMKrKxOFTKstFzx6PMqGXZohxRV5hnFhmYWPPV00O 8QJC+SinMuNbFqrnat8pW+pH6cGzGWH48CqNIDDaC68hvp2PWWVnlNYHDsZ5G4drv9gl qwbd8T4yAb7q6PD3QCfCEEYMCykAps/G5TGrI766dnZjPonx0wKopjZboFY1xDI543UF G6WcOQa8ND/OoTWcXxQ/MnvC9RXgV8Acb1rqGIXwrMe+j1CDmihrcY5vrIWGIWyCGV9u 6LrDPrg0Wk/xUcr709m0M2vzspAI7uUUGsqYLbwYvR0TlhjsgjDciS1uR54j1Pg46Hl+ BugQ== 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=ameaOYTaejX0n/etuEC9PIIeVKsPKESqsBuicmuydr8=; b=Kv/TQFrWXdyA87inganhpV8AyPOiW2xfOmE1L3B//vdyJQzYn7hwyMNGgzpFVlZx5g 0eHzAKJaGny3rdLhEOhaJy+5y9bXXngOdD6k0Bb+tgIPDmjKqQlMv0U0MF0msasjDzsy 2yZGOEE0oWBuGQvBBsq2vFLYMi2Suk0SdMFDBGed0sOBXrr0N8lXC4iXqE6mRQYjtMqX TYYStLA0vRCMXUYxqsXhqdHGAHSzZeOR6W2RApWNrnTk4ZazSN0/nihzhYeb62TGO40e wVTz/zzn/A5pNy6VXwYRlOMkMe7xsc3fJuTlgaVTnzw5hWng/W4N9zsKGFln2tLM9Mtx heBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IsMnhkWb; 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 v15-20020ac8728f000000b0031d3ea50dd8si4925060qto.493.2022.07.11.23.42.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Jul 2022 23:42:22 -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=IsMnhkWb; 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]:39574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oB9bB-00085a-Cm for patch@linaro.org; Tue, 12 Jul 2022 02:42:22 -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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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_ulong addr, uint64_t val, const size_t tlb_off = 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_ulong 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 = addr & TARGET_PAGE_MASK; page2 = (addr + size) & TARGET_PAGE_MASK; size2 = (addr + size) & ~TARGET_PAGE_MASK; index2 = tlb_index(env, mmu_idx, page2); entry2 = tlb_entry(env, mmu_idx, page2); tlb_addr2 = tlb_addr_write(entry2); - if (!tlb_hit_page(tlb_addr2, page2)) { + if (page1 != 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);