From nobody Sat May 18 16:18:07 2024 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=yadro.com ARC-Seal: i=1; a=rsa-sha256; t=1691060405; cv=none; d=zohomail.com; s=zohoarc; b=K3fCsPLo8UwtOvMM+RkAvAchaQWnesPD52CW5zpHHwa17mGkYw8+soXkMIAJl8RTW9ZqS0l6XJUVCk/ZEi6j5koh8lI6pTL/WUL0UTqahd7ZO3jN1L15VLoQuKf/2d0w9RQ86X7gG0cIOY/AM58vybkpCUy4sMqqWmS8hyPW7k0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691060405; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=6M9XNZqC6+PwpcxI1EL+AQwcwoslHx9KXxpKEm8R1IE=; b=fqIujWw8HDGoQX5sEl0jGw4t7X7QmCGRdWzFCs2gntxjj1VsPkXrPb7QRQmJjsWaZfTWO6Nx8zomUTYpiHI2rOVOeYjhluArnGWZXyUslgGGPKd5xcU8XRKA0qAZq9ssqPP+n/1YRBTwy3uU06XH0gukD+OKvCewz/7w7TLWA50= 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 1691060405413764.5759699462085; Thu, 3 Aug 2023 04:00:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qRW34-0006kq-UK; Thu, 03 Aug 2023 06:59:19 -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 1qRW32-0006XZ-W9 for qemu-devel@nongnu.org; Thu, 03 Aug 2023 06:59:17 -0400 Received: from mta-04.yadro.com ([89.207.88.248]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qRW30-0002OH-5W for qemu-devel@nongnu.org; Thu, 03 Aug 2023 06:59:16 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 mta-04.yadro.com 2CCBAC0003 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yadro.com; s=mta-04; t=1691060350; bh=6M9XNZqC6+PwpcxI1EL+AQwcwoslHx9KXxpKEm8R1IE=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=W24BtGcCL535opZvmamOPvtUxxNQwnFyOx4noWwMtRdfCtP6pPssKhx0TlSb/De95 J3kRNMOguVW1kk+mMxHQECL+PdVL3Yg/yxu3WIoqeXHO1LAjn4iy+gsoOPsPVbB4xa B1I8584lBEo+/4Lp1R+SBM2p8AZM9OnSwVZRrpOEMvY5ok+oN+054bEsQyQuAP4v+Z idiPNHC7trqmqLaaqRq+Drmi/cBE2dfX4jPsS++R40SAhvsXU2yyRCrwO2WwQhqECI 7SR1/FjwCcjLjm/I4ZEStUnzmY67NnCZcfcdPFm6GOnvIATzuvQUn7sGyoUb9ZVTgJ F0LTY4UUrTpvQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yadro.com; s=mta-03; t=1691060350; bh=6M9XNZqC6+PwpcxI1EL+AQwcwoslHx9KXxpKEm8R1IE=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=RuICXRyB/rNFgRbjxV2FvtFlSurGLl0Lh5fxdz4vY0zEliGZWTsGaxuhfzZH20Vgp 6yO19p77fTunbgwUX7yVxB4MwlXgCz5iH0m+XADUdgyuwgJvAwrC6GWHe9NAV8zjet 3DuwQDUD32jQFZyIzkHRuZZUylZ8wZ/5aIDTMfkp6kuVB5OgmKFsHm0DXETfSD4EFb KTLFP5xPi79eAstFL41X9F2npda6E7E06kd9YoRWCvEKfmVEmu6zbOYiLlTD8xHixY iiD/QlKQn+/7wHzvpDVDPqZiGJezSvLxCA7o7ngtv/FyYFb+MUZFCQw4lU1AwtOXTC h82T8PfQ+TZDA== From: Mikhail Tyutin To: CC: , , , Mikhail Tyutin , Dmitriy Solovev Subject: [PATCH v2] Fix SEGFAULT on getting physical address of MMIO region. Date: Thu, 3 Aug 2023 13:58:30 +0300 Message-ID: <20230803105830.8722-1-m.tyutin@yadro.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: T-EXCH-06.corp.yadro.com (172.17.10.110) To T-EXCH-08.corp.yadro.com (172.17.11.58) 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=89.207.88.248; envelope-from=m.tyutin@yadro.com; helo=mta-04.yadro.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, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yadro.com) (identity @yadro.com) X-ZM-MESSAGEID: 1691060408756100001 Content-Type: text/plain; charset="utf-8" Apply save_iotlb_data() to io_readx() as well as to io_writex(). Signed-off-by: Dmitriy Solovev Signed-off-by: Mikhail Tyutin Reviewed-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 ba44501a7c..addce3be38 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, } } =20 +/* + * 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 =3D &cs->saved_iotlb; + saved->section =3D section; + saved->mr_offset =3D 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, CPUTLBEn= tryFull *full, cpu_io_recompile(cpu, retaddr); } =20 + /* + * 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 =3D memory_region_dispatch_read(mr, mr_offset, &val, op, full->a= ttrs); @@ -1398,21 +1419,6 @@ static uint64_t io_readx(CPUArchState *env, CPUTLBEn= tryFull *full, return val; } =20 -/* - * 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 =3D &cs->saved_iotlb; - saved->section =3D section; - saved->mr_offset =3D mr_offset; -#endif -} - static void io_writex(CPUArchState *env, CPUTLBEntryFull *full, int mmu_idx, uint64_t val, vaddr addr, uintptr_t retaddr, MemOp op) --=20 2.34.1