From patchwork Sun Aug 6 03:37:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 710864 Delivered-To: patch@linaro.org Received: by 2002:a05:6359:d30:b0:129:c516:61db with SMTP id gp48csp825929rwb; Sat, 5 Aug 2023 20:38:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE94DxPIPPYmSYMrndpkPMRv2P8benCrXHrnZEtOyKAMuMGQGkSTsDPedKswnoj8OuP5A6n X-Received: by 2002:a05:6870:a113:b0:1bb:8483:a805 with SMTP id m19-20020a056870a11300b001bb8483a805mr7133414oae.32.1691293091711; Sat, 05 Aug 2023 20:38:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691293091; cv=none; d=google.com; s=arc-20160816; b=0+zQjy8OeOR+SSUmiMMI7phlI/OTSirdFVwbXC5LcdnAbWtW3oV31lVTU4OxudGqnE y6E7gkUWyBq4kERg/iDxKN7r9sLsTOalhzekrhbHK4lv//bZ6RnROKQruRu/qzyW6s/+ mgDBaJ+32pXb0G04ldbvgH0iyVJL0gKYrRbmwbyw9jV9OWq72Gg1Ve7RrmajiIxludn9 J5BiRnuvoFovX2X5zv8YTGIIKO7mENaGFz4StffHexVuSVyNwaW8Trc9oBxbTORHnKjX Enx56hsqLd1IUG6bA/SBUzT0DSlrAmqbWOSZ/eCus/hOWFsIprqK428JmBAgBwJRHdvz 7GlQ== 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=lfYi3zP2whYYhdilrdAtUwTS+wOZ/T9TUKhhh0JmADM=; fh=Q92HZIlqtyucC1SOx0hVIY0BQ6aYzDDOpcVF7DuLR5k=; b=BMKJjjGXGsnMEMTIfBXhRcpnakRo20le9uibaO3d8vK+vYqzIkriWZupszk+Ra25No /C/f9tj9BJIyB26MrhZC+w4t3NOm9+Aq178oxBgzVBSxMuAtmYvLnVmii4aC03UZJweJ QKT6BQxgB7OfSibAXmxFMr4E1vrwI8ROrMUbryiQpwPytkZ4i1bUBAqBRpqJsFwGQagV GYz0SI/SgHJDdvalG1CHYtDmClnzXe+cYkomAWMRHkibqOq9LGMVkhGLfemnVsqW+Nie TyejPyv6aCY2QUUor4zOjIgsj6kQ+LolqXOqUka8hZkL27KtKhP1UvGCOmaNZiwBVxRE eYNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HdyPok+3; 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 j4-20020a05620a410400b0076799979daasi3401800qko.238.2023.08.05.20.38.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 05 Aug 2023 20:38:11 -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=HdyPok+3; 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 1qSUaL-0003lD-7g; Sat, 05 Aug 2023 23:37:41 -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 1qSUaI-0003jw-6L for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:38 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qSUaG-0007bV-IW for qemu-devel@nongnu.org; Sat, 05 Aug 2023 23:37:37 -0400 Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-268128a0105so2263148a91.3 for ; Sat, 05 Aug 2023 20:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691293055; x=1691897855; 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=lfYi3zP2whYYhdilrdAtUwTS+wOZ/T9TUKhhh0JmADM=; b=HdyPok+35A++RKX3yC0PF7hseKukkof6kahARC9kKVXK6WUkzluMycTr6fDE6K576c RyDl2kfcDH1jczDplg9no9tNPr3DQd+VtOZ0lTq9cY26+0XScCm9Up/jqInUx5NuFhAR 7J7fmuh6TenmTm0ovFOXlg+GedT9ykcf5XYnPmglTX/92k8eWcvQyR1nAcOvUYEzUoE0 9mTI2q+jZ2IxA0GYEVOvI5NzM+mPPvFqGIlfF7IBG4DRAKrTTvKd2bukUGq+dFKFPCVj X25jz99cXiGyvhH49eS+F7qdYXHRrP9J7W8NPAYNr1fpvOmojayb51YsgyFhPMLmPf0N SoAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691293055; x=1691897855; 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=lfYi3zP2whYYhdilrdAtUwTS+wOZ/T9TUKhhh0JmADM=; b=WYV1ywJ/jRoZWX4eCP7aNPtS2lYxREECz7TZLxmjlNF2qWKVqjjyaXmI/42YDXHAy4 UsPkvxHfCx5pAWVK0+wDsKByOFvky+X60jzX4zytAQTejTJrsdKY3zr1JHMEhNRN4Hsi d488dYLSirPkX1cfJU7Axhh5cfDFadnIgdFOiAoESMi+LRQ7pFOWkOZRTUdLVCszkWhM EdnSr3NM1/XIA4G+mnOSzGYAK0dF7pTtqZihW+ZAsSY48NdgEiANC/Sn0D9kPQqCNp5C /ajlzYsrFa5+wxIXgWvzAyGZhqdmaT1JwpzUmz/Q5VccWQ7UeyQfL4ELu+wYjvSLq/Zo bPYQ== X-Gm-Message-State: AOJu0YzEe5l3MCBe/EeS/P/AWW7Xjv7gU2dLmR6JFKxrN/+59HC1GlNR c/VwlkcFqWQME3yHjmC83tgojt9pbxQDH5TE+ng= X-Received: by 2002:a17:90a:eb07:b0:267:a859:dfef with SMTP id j7-20020a17090aeb0700b00267a859dfefmr5281440pjz.27.1691293055326; Sat, 05 Aug 2023 20:37:35 -0700 (PDT) Received: from stoup.. ([2602:47:d490:6901:9454:a46f:1c22:a7c6]) by smtp.gmail.com with ESMTPSA id a5-20020a17090a740500b00262e604724dsm6306451pjg.50.2023.08.05.20.37.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 20:37:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Mikhail Tyutin , Dmitriy Solovev Subject: [PULL 23/24] accel/tcg: Call save_iotlb_data from io_readx as well. Date: Sat, 5 Aug 2023 20:37:14 -0700 Message-Id: <20230806033715.244648-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230806033715.244648-1-richard.henderson@linaro.org> References: <20230806033715.244648-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.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: Mikhail Tyutin Apply save_iotlb_data() to io_readx() as well as to io_writex(). This fixes SEGFAULT on qemu_plugin_hwaddr_phys_addr() call plugins for addresses inside of MMIO region. Signed-off-by: Dmitriy Solovev Signed-off-by: Mikhail Tyutin Reviewed-by: Richard Henderson Message-Id: <20230804110903.19968-1-m.tyutin@yadro.com> Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 4b1bfaa53d..d68fa6867c 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1363,6 +1363,21 @@ static inline void cpu_transaction_failed(CPUState *cpu, hwaddr physaddr, } } +/* + * Save a potentially trashed CPUTLBEntryFull for later lookup by plugin. + * This is read by tlb_plugin_lookup if the fulltlb entry doesn't match + * because of the side effect of io_writex changing memory layout. + */ +static void save_iotlb_data(CPUState *cs, MemoryRegionSection *section, + hwaddr mr_offset) +{ +#ifdef CONFIG_PLUGIN + SavedIOTLB *saved = &cs->saved_iotlb; + saved->section = section; + saved->mr_offset = mr_offset; +#endif +} + static uint64_t io_readx(CPUArchState *env, CPUTLBEntryFull *full, int mmu_idx, vaddr addr, uintptr_t retaddr, MMUAccessType access_type, MemOp op) @@ -1382,6 +1397,12 @@ static uint64_t io_readx(CPUArchState *env, CPUTLBEntryFull *full, cpu_io_recompile(cpu, retaddr); } + /* + * The memory_region_dispatch may trigger a flush/resize + * so for plugins we save the iotlb_data just in case. + */ + save_iotlb_data(cpu, section, mr_offset); + { QEMU_IOTHREAD_LOCK_GUARD(); r = memory_region_dispatch_read(mr, mr_offset, &val, op, full->attrs); @@ -1398,21 +1419,6 @@ static uint64_t io_readx(CPUArchState *env, CPUTLBEntryFull *full, return val; } -/* - * Save a potentially trashed CPUTLBEntryFull for later lookup by plugin. - * This is read by tlb_plugin_lookup if the fulltlb entry doesn't match - * because of the side effect of io_writex changing memory layout. - */ -static void save_iotlb_data(CPUState *cs, MemoryRegionSection *section, - hwaddr mr_offset) -{ -#ifdef CONFIG_PLUGIN - SavedIOTLB *saved = &cs->saved_iotlb; - saved->section = section; - saved->mr_offset = mr_offset; -#endif -} - static void io_writex(CPUArchState *env, CPUTLBEntryFull *full, int mmu_idx, uint64_t val, vaddr addr, uintptr_t retaddr, MemOp op)