From nobody Sun May 5 06:43:46 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=163.com ARC-Seal: i=1; a=rsa-sha256; t=1599583422; cv=none; d=zohomail.com; s=zohoarc; b=BmzkYBJESdmBK8FXlZA/jN4aBOcAE4mJNj7MoscCojn38Vh6ILDmUDzBqkIcuxFK/yNxVkQhhXABGyv47ntqD+BmKhVJx43WLewbGh6i535h+DImWYd0rKVhLcVMpl5kExLoyl4a6DjsjkHZHanv8hYN9J9ipH+jUfbdP01oBEI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599583422; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=6o6Keb5oFii1iCN3xIh04mis0S3GAV4u9wS5ltt8Iao=; b=P9f16CvAZNOb3tEpi7MpUiIpzP80d5uKFN60AT3bJpi6SxnZRkdrG76Gff0sd0QDh61iAxWt4jusKIG33vB/spTaA4inSCBguUVD+L4YAEC0lsM2uOCzp/CIj2gMZDe5/epOW3CR5ZQmlwXvrThG+sTuSPde45rE8SXjga5+gyk= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1599583422770265.7918350366897; Tue, 8 Sep 2020 09:43:42 -0700 (PDT) Received: from localhost ([::1]:49388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kFgia-0008LA-NC for importer@patchew.org; Tue, 08 Sep 2020 12:43:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFghW-00075L-Mt for qemu-devel@nongnu.org; Tue, 08 Sep 2020 12:42:34 -0400 Received: from mail-m975.mail.163.com ([123.126.97.5]:49856) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kFghR-0002LP-GR for qemu-devel@nongnu.org; Tue, 08 Sep 2020 12:42:33 -0400 Received: from localhost.localdomain (unknown [183.158.94.209]) by smtp5 (Coremail) with SMTP id HdxpCgCnGRhetFdf9j7RJg--.1087S5; Wed, 09 Sep 2020 00:42:09 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=6o6Keb5oFii1iCN3xI h04mis0S3GAV4u9wS5ltt8Iao=; b=ev3Nk22JBi+5itTFJJn3QhYmJmo0HJvfgP 6vgZHfY5jEV/9efBYTNu7+xuAnbyG7Y4PNm/EhgzkMlGgZmRIULFsWyWnvbF7PNn OqpbowiwJfbAJ6+EvHg662BqDgWxOaT2AS3oREri7e56XMzATFFRMrx1eQk9iv7+ vzzPhJoHw= From: Li Qiang To: dmitry.fleytman@gmail.com, jasowang@redhat.com, kraxel@redhat.com, pbonzini@redhat.com, berrange@redhat.com, ehabkost@redhat.com, alxndr@bu.edu, peter.maydell@linaro.org, f4bug@amsat.org Subject: [RFC 1/4] memory: add memory_region_init_io_with_dev interface Date: Tue, 8 Sep 2020 09:41:54 -0700 Message-Id: <20200908164157.47108-2-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200908164157.47108-1-liq3ea@163.com> References: <20200908164157.47108-1-liq3ea@163.com> X-CM-TRANSID: HdxpCgCnGRhetFdf9j7RJg--.1087S5 X-Coremail-Antispam: 1Uf129KBjvJXoW7ZrW8ZF1kur48Kr1DKw47CFg_yoW8CF1kpF 97uF9Ygr48tF9xZF1ftF4DWFyrA3y8K3W7Cr9rZwn2krs7tF9xArWUG345AryUCrWUX3W5 XFyUXr4fuan5J3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRaYL9UUUUU= X-Originating-IP: [183.158.94.209] X-CM-SenderInfo: 5oltjvrd6rljoofrz/1tbiKQGZbVXlxmTITQAAsL 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=123.126.97.5; envelope-from=liq3ea@163.com; helo=mail-m975.mail.163.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/08 12:42:19 X-ACL-Warn: Detected OS = Linux 3.1-3.10 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, FREEMAIL_FROM=0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @163.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently the MR is not explicitly connecting with its device instead of a opaque. In most situation this opaque is the deivce but it is not an enforcement. This patch adds a DeviceState member of to MemoryRegion we will use it in later patch. Signed-off-by: Li Qiang --- include/exec/memory.h | 9 +++++++++ softmmu/memory.c | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index 0cfe987ab4..620fb12d9b 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -404,6 +404,7 @@ struct MemoryRegion { const char *name; unsigned ioeventfd_nb; MemoryRegionIoeventfd *ioeventfds; + DeviceState *dev; }; =20 struct IOMMUMemoryRegion { @@ -794,6 +795,14 @@ void memory_region_init_io(MemoryRegion *mr, const char *name, uint64_t size); =20 +void memory_region_init_io_with_dev(MemoryRegion *mr, + struct Object *owner, + const MemoryRegionOps *ops, + void *opaque, + const char *name, + uint64_t size, + DeviceState *dev); + /** * memory_region_init_ram_nomigrate: Initialize RAM memory region. Acces= ses * into the region will modify memory diff --git a/softmmu/memory.c b/softmmu/memory.c index 70b93104e8..2628c9d2d9 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1490,6 +1490,21 @@ void memory_region_init_io(MemoryRegion *mr, mr->terminates =3D true; } =20 +void memory_region_init_io_with_dev(MemoryRegion *mr, + Object *owner, + const MemoryRegionOps *ops, + void *opaque, + const char *name, + uint64_t size, + DeviceState *dev) +{ + memory_region_init(mr, owner, name, size); + mr->ops =3D ops ? ops : &unassigned_mem_ops; + mr->opaque =3D opaque; + mr->terminates =3D true; + mr->dev =3D dev; +} + void memory_region_init_ram_nomigrate(MemoryRegion *mr, Object *owner, const char *name, --=20 2.17.1 From nobody Sun May 5 06:43:46 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=163.com ARC-Seal: i=1; a=rsa-sha256; t=1599583514; cv=none; d=zohomail.com; s=zohoarc; b=DG9hYW03txNMlBzKrsmjUA7AK20e/EnUswrJ4J/eW3S2tk5+YhZgYaKHeH245glNyDP1e/De/YXaYWPBZBXARCbqiL9M5RyF0LlNf0mT4AK5jMu3esNe4dVnW4X2BnhOzPHECMEQ3srVgXy951UlGbaCSAtXHslfrzQFIFXdTCQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599583514; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=kfHlVeS9NRlcIquOpEso70dCCBVTxtqozqqcBgk4xCI=; b=m1zC2TGnLtp7WCCxzkpPXtOxIU93YqksgdKbKbciHoo9I96zI0TkEjofKU3hMv1f/qw3WMd4mbdawPag0FiEi6nOMQMngk2QQruhqOYQ3NFhp8ZirrXSFBF/GRW6Y1npLn6WhDfJle7MSM5KKw2G4ZyH1eJADv1mxUzLOLApPBM= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159958351479321.156413232959835; Tue, 8 Sep 2020 09:45:14 -0700 (PDT) Received: from localhost ([::1]:54674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kFgk5-00028v-GZ for importer@patchew.org; Tue, 08 Sep 2020 12:45:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFghX-00075b-BR for qemu-devel@nongnu.org; Tue, 08 Sep 2020 12:42:35 -0400 Received: from mail-m975.mail.163.com ([123.126.97.5]:49880) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kFghT-0002Le-2P for qemu-devel@nongnu.org; Tue, 08 Sep 2020 12:42:35 -0400 Received: from localhost.localdomain (unknown [183.158.94.209]) by smtp5 (Coremail) with SMTP id HdxpCgCnGRhetFdf9j7RJg--.1087S6; Wed, 09 Sep 2020 00:42:11 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=kfHlVeS9NRlcIquOpE so70dCCBVTxtqozqqcBgk4xCI=; b=KT544sAKXymAjlr5IuOgCw6y91NvKToB2x 9Vylr+wVmSyhXqoK0V8WgzTuhz0AFV1pLzTSbagPYXibXPVPIg4qLHOB8Nk8XYrk 2T2iqZoW5X7PN/Dngo7zE4OP8n3KAm4CruH+oGR2mU418O+5MCvn4ZnlffvlvU9J /OcTwXONg= From: Li Qiang To: dmitry.fleytman@gmail.com, jasowang@redhat.com, kraxel@redhat.com, pbonzini@redhat.com, berrange@redhat.com, ehabkost@redhat.com, alxndr@bu.edu, peter.maydell@linaro.org, f4bug@amsat.org Subject: [RFC 2/4] memory: avoid reenter the device's MMIO handler while processing MMIO Date: Tue, 8 Sep 2020 09:41:55 -0700 Message-Id: <20200908164157.47108-3-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200908164157.47108-1-liq3ea@163.com> References: <20200908164157.47108-1-liq3ea@163.com> X-CM-TRANSID: HdxpCgCnGRhetFdf9j7RJg--.1087S6 X-Coremail-Antispam: 1Uf129KBjvJXoW7tF43WF18ZrW7Gr17Zw4ruFg_yoW8Kw47pF yxXF9Y9rW0yFnrArySqrW3XF15C3y8GFnrG3sxCr97urn7tF15ZrnYg345Aryxtr98Xay5 WrZ8XFW3Ww1rJw7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07U6VbkUUUUU= X-Originating-IP: [183.158.94.209] X-CM-SenderInfo: 5oltjvrd6rljoofrz/xtbBZgOZbVaD53waCQAAsM 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=123.126.97.5; envelope-from=liq3ea@163.com; helo=mail-m975.mail.163.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/08 12:42:19 X-ACL-Warn: Detected OS = Linux 3.1-3.10 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, FREEMAIL_FROM=0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @163.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds a 'in_mmio' flag to 'DeviceState' to indicate that the device is doing MMIO path. This can avoid the malicious guest do DMA to MMIO and crash the qemu. Signed-off-by: Li Qiang --- include/hw/qdev-core.h | 1 + softmmu/memory.c | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index ea3f73a282..c6f4ebba9e 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -177,6 +177,7 @@ struct DeviceState { char *canonical_path; bool realized; bool pending_deleted_event; + bool in_mmio; QemuOpts *opts; int hotplugged; bool allow_unplug_during_migration; diff --git a/softmmu/memory.c b/softmmu/memory.c index 2628c9d2d9..7be44f7175 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -1410,8 +1410,20 @@ MemTxResult memory_region_dispatch_read(MemoryRegion= *mr, return MEMTX_DECODE_ERROR; } =20 + if (mr->dev) { + if (mr->dev->in_mmio) { + return MEMTX_ERROR; + } else { + mr->dev->in_mmio =3D true; + } + } + r =3D memory_region_dispatch_read1(mr, addr, pval, size, attrs); adjust_endianness(mr, pval, op); + + if (mr->dev) { + mr->dev->in_mmio =3D false; + } return r; } =20 @@ -1448,6 +1460,7 @@ MemTxResult memory_region_dispatch_write(MemoryRegion= *mr, MemTxAttrs attrs) { unsigned size =3D memop_size(op); + MemTxResult ret; =20 if (!memory_region_access_valid(mr, addr, size, true, attrs)) { unassigned_mem_write(mr, addr, data, size); @@ -1461,20 +1474,32 @@ MemTxResult memory_region_dispatch_write(MemoryRegi= on *mr, return MEMTX_OK; } =20 + if (mr->dev) { + if (mr->dev->in_mmio) { + return MEMTX_ERROR; + } else { + mr->dev->in_mmio =3D true; + } + } + if (mr->ops->write) { - return access_with_adjusted_size(addr, &data, size, + ret =3D access_with_adjusted_size(addr, &data, size, mr->ops->impl.min_access_size, mr->ops->impl.max_access_size, memory_region_write_accessor, mr, attrs); } else { - return - access_with_adjusted_size(addr, &data, size, + ret =3D access_with_adjusted_size(addr, &data, size, mr->ops->impl.min_access_size, mr->ops->impl.max_access_size, memory_region_write_with_attrs_acces= sor, mr, attrs); } + if (mr->dev) { + mr->dev->in_mmio =3D false; + } + + return ret; } =20 void memory_region_init_io(MemoryRegion *mr, --=20 2.17.1 From nobody Sun May 5 06:43:46 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=163.com ARC-Seal: i=1; a=rsa-sha256; t=1599583423; cv=none; d=zohomail.com; s=zohoarc; b=AQdG7hkw82P6P88hUU7BdQGu83MmIpULLPOteBihznRKBVYPo0/MwZHXd5h/1k4Cfd9O1R3aTPxTkToLDu1hGvvih/bRCk4PEKjLEMgZZ7CH8sSv9TjWQLTYGGxLIwVmV/n6I5WgNpaFFQ0ix02cM7aNDvZiyAVj2hFBxQc0NTw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599583423; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=sPsqanpMwV8rF74svaZiLXEHyS8k70SBROldCWnc19c=; b=QJ/iwxBqrxVeXWbjaDrYkwW0bZ5qMaXa/JC+YcttMSHUpAHUQgO+zSP+IaATHVDqdx6DxVRsJFNd1XfxEHOfSO1KiKFJZLPTcEz683ZV5hZTJm1VBo5N6htqn6S4EMo4CaQAZyR6xCWU8dJzRBtUytbJXKLyiz2SveP/Adw3JeQ= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1599583423022526.640887897471; Tue, 8 Sep 2020 09:43:43 -0700 (PDT) Received: from localhost ([::1]:49436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kFgia-0008MH-KA for importer@patchew.org; Tue, 08 Sep 2020 12:43:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFghW-00075N-E7 for qemu-devel@nongnu.org; Tue, 08 Sep 2020 12:42:34 -0400 Received: from mail-m975.mail.163.com ([123.126.97.5]:49878) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kFghS-0002Lc-MY for qemu-devel@nongnu.org; Tue, 08 Sep 2020 12:42:33 -0400 Received: from localhost.localdomain (unknown [183.158.94.209]) by smtp5 (Coremail) with SMTP id HdxpCgCnGRhetFdf9j7RJg--.1087S7; Wed, 09 Sep 2020 00:42:12 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=sPsqanpMwV8rF74sva ZiLXEHyS8k70SBROldCWnc19c=; b=E0jL09vlZ4vdpEaza0ZruF3Go798GSvsve SAy5K4QcTeXdSlIZL58szZ1/cOADnyM8D9fpQkWxvnEMMYaIuMLmjODLJ5m0dJi1 W+iGmVvJQHsQcI7cWeMLNqXhE8f8JaNI9exgP6L6jca/cGIdd3mceBgMs+k5J5k5 eL2+BNltQ= From: Li Qiang To: dmitry.fleytman@gmail.com, jasowang@redhat.com, kraxel@redhat.com, pbonzini@redhat.com, berrange@redhat.com, ehabkost@redhat.com, alxndr@bu.edu, peter.maydell@linaro.org, f4bug@amsat.org Subject: [RFC 3/4] e1000e: use the new memory_region_init_io_with_dev interface Date: Tue, 8 Sep 2020 09:41:56 -0700 Message-Id: <20200908164157.47108-4-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200908164157.47108-1-liq3ea@163.com> References: <20200908164157.47108-1-liq3ea@163.com> X-CM-TRANSID: HdxpCgCnGRhetFdf9j7RJg--.1087S7 X-Coremail-Antispam: 1Uf129KBjvJXoW7Cw18ZF45XF43WF1kJrWxCrg_yoW8Gry7p3 yfJ3Z5uryrtFZFvF429F18WFn5JwsFq348Cr4UZw4Sga9FgF1qyr1FyF4ayrWI9ayUAryr Za18tryI9w4DtwUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jb0eQUUUUU= X-Originating-IP: [183.158.94.209] X-CM-SenderInfo: 5oltjvrd6rljoofrz/1tbiKQaZbVXlxmTIXwAAse 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=123.126.97.5; envelope-from=liq3ea@163.com; helo=mail-m975.mail.163.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/08 12:42:19 X-ACL-Warn: Detected OS = Linux 3.1-3.10 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, FREEMAIL_FROM=0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @163.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This can avoid the DMA to MMIO issue here: https://bugs.launchpad.net/qemu/+bug/1886362 Signed-off-by: Li Qiang --- hw/net/e1000e.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/net/e1000e.c b/hw/net/e1000e.c index fda34518c9..0aac5cea2e 100644 --- a/hw/net/e1000e.c +++ b/hw/net/e1000e.c @@ -439,8 +439,8 @@ static void e1000e_pci_realize(PCIDevice *pci_dev, Erro= r **errp) s->subsys_used =3D s->subsys; =20 /* Define IO/MMIO regions */ - memory_region_init_io(&s->mmio, OBJECT(s), &mmio_ops, s, - "e1000e-mmio", E1000E_MMIO_SIZE); + memory_region_init_io_with_dev(&s->mmio, OBJECT(s), &mmio_ops, s, + "e1000e-mmio", E1000E_MMIO_SIZE, &pci_dev->qdev); pci_register_bar(pci_dev, E1000E_MMIO_IDX, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mmio); =20 @@ -453,8 +453,8 @@ static void e1000e_pci_realize(PCIDevice *pci_dev, Erro= r **errp) pci_register_bar(pci_dev, E1000E_FLASH_IDX, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->flash); =20 - memory_region_init_io(&s->io, OBJECT(s), &io_ops, s, - "e1000e-io", E1000E_IO_SIZE); + memory_region_init_io_with_dev(&s->io, OBJECT(s), &io_ops, s, + "e1000e-io", E1000E_IO_SIZE, &pci_dev->qdev); pci_register_bar(pci_dev, E1000E_IO_IDX, PCI_BASE_ADDRESS_SPACE_IO, &s->io); =20 --=20 2.17.1 From nobody Sun May 5 06:43:46 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=163.com ARC-Seal: i=1; a=rsa-sha256; t=1599583424; cv=none; d=zohomail.com; s=zohoarc; b=LUmI8tmvj7Su1yUtldRaq65jx9JRIf7htbfQMA5oZG2fxb+DvJxZJAFMNvOh2nmzBiOC8Ci2Rbr/4Wof30khZh4DwGOzsWFT335yC/KYtrprMJFBPjKBFS6y8wgeuD+CV8lpibQQ8G9DMxAyKGCWwLNZyE/AyOhh2368UYOPnAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599583424; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=ue6ZFmUxcoAPwFD/W8EjddlF4L1dxZ5iyH/qq+Mkd7Q=; b=Mh+3kyfmjE35bynIrhjhTZX1wjTt2IjTqlRWCQVZctZF15pfStV1TR5B2iSW4t9raLNKWtaDrDWNR4hTG64izF67gU6+EUpQhL9szGwJrV85Bj6UtkBegJFXRLXDrPeUz36NANJ1flEbVT3aBZXpa5oed/Nb/xcu2OCt142a7/4= 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) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1599583424135727.7039023376902; Tue, 8 Sep 2020 09:43:44 -0700 (PDT) Received: from localhost ([::1]:49620 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kFgic-0008Qs-RX for importer@patchew.org; Tue, 08 Sep 2020 12:43:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49528) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFghY-00075w-22 for qemu-devel@nongnu.org; Tue, 08 Sep 2020 12:42:36 -0400 Received: from mail-m975.mail.163.com ([123.126.97.5]:49894) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kFghV-0002Lj-Sc for qemu-devel@nongnu.org; Tue, 08 Sep 2020 12:42:35 -0400 Received: from localhost.localdomain (unknown [183.158.94.209]) by smtp5 (Coremail) with SMTP id HdxpCgCnGRhetFdf9j7RJg--.1087S8; Wed, 09 Sep 2020 00:42:15 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=ue6ZFmUxcoAPwFD/W8 EjddlF4L1dxZ5iyH/qq+Mkd7Q=; b=i1VTksq9cypu4xvCMDCvtI5anP35ZHT7/V kvpQx75HCJXNXQ2oSNsjPvK7hR8FzJaUWhdxmrn729R6kL+E77+uJzKCdE31o5Cw lsXNcx76xC8TdEC0L06Y7vSirqLtljNYxn7MNWGcgB8EH0mKneHxQdPoisbPdDhF RnQJQ1w7U= From: Li Qiang To: dmitry.fleytman@gmail.com, jasowang@redhat.com, kraxel@redhat.com, pbonzini@redhat.com, berrange@redhat.com, ehabkost@redhat.com, alxndr@bu.edu, peter.maydell@linaro.org, f4bug@amsat.org Subject: [RFC 4/4] hcd-xhci: use the new memory_region_init_io_with_dev interface Date: Tue, 8 Sep 2020 09:41:57 -0700 Message-Id: <20200908164157.47108-5-liq3ea@163.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200908164157.47108-1-liq3ea@163.com> References: <20200908164157.47108-1-liq3ea@163.com> X-CM-TRANSID: HdxpCgCnGRhetFdf9j7RJg--.1087S8 X-Coremail-Antispam: 1Uf129KBjvJXoW7KFykCFWfGF18ZrWxGr15urg_yoW8KFy5pF 4fXas8WryfJFnIqrsxta1kZFs5A34kKryxGFyxA3sFqFs2kw1qya1Iyw1FkF97KrykJr45 XF4rJF1fWw1DJaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UzmhrUUUUU= X-Originating-IP: [183.158.94.209] X-CM-SenderInfo: 5oltjvrd6rljoofrz/xtbBZgeZbVaD53waIAAAsh 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=123.126.97.5; envelope-from=liq3ea@163.com; helo=mail-m975.mail.163.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/08 12:42:19 X-ACL-Warn: Detected OS = Linux 3.1-3.10 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, FREEMAIL_FROM=0.001, 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Li Qiang , liq3ea@gmail.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @163.com) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This can avoid the DMA to MMIO issue here: https://bugs.launchpad.net/qemu/+bug/1891354 Signed-off-by: Li Qiang --- hw/usb/hcd-xhci.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 46a2186d91..1954ae2ae7 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -3437,14 +3437,18 @@ static void usb_xhci_realize(struct PCIDevice *dev,= Error **errp) xhci->mfwrap_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, xhci_mfwrap_ti= mer, xhci); =20 memory_region_init(&xhci->mem, OBJECT(xhci), "xhci", LEN_REGS); - memory_region_init_io(&xhci->mem_cap, OBJECT(xhci), &xhci_cap_ops, xhc= i, - "capabilities", LEN_CAP); - memory_region_init_io(&xhci->mem_oper, OBJECT(xhci), &xhci_oper_ops, x= hci, - "operational", 0x400); - memory_region_init_io(&xhci->mem_runtime, OBJECT(xhci), &xhci_runtime_= ops, xhci, - "runtime", LEN_RUNTIME); - memory_region_init_io(&xhci->mem_doorbell, OBJECT(xhci), &xhci_doorbel= l_ops, xhci, - "doorbell", LEN_DOORBELL); + memory_region_init_io_with_dev(&xhci->mem_cap, OBJECT(xhci), + &xhci_cap_ops, xhci, + "capabilities", LEN_CAP, &dev->qdev); + memory_region_init_io_with_dev(&xhci->mem_oper, OBJECT(xhci), + &xhci_oper_ops, xhci, + "operational", 0x400, &dev->qdev); + memory_region_init_io_with_dev(&xhci->mem_runtime, OBJECT(xhci), + &xhci_runtime_ops, xhci, + "runtime", LEN_RUNTIME, &dev->qdev); + memory_region_init_io_with_dev(&xhci->mem_doorbell, OBJECT(xhci), + &xhci_doorbell_ops, xhci, + "doorbell", LEN_DOORBELL, &dev->qdev); =20 memory_region_add_subregion(&xhci->mem, 0, &xhci->mem_cap); memory_region_add_subregion(&xhci->mem, OFF_OPER, &xhci->mem_oper); @@ -3455,8 +3459,9 @@ static void usb_xhci_realize(struct PCIDevice *dev, E= rror **errp) XHCIPort *port =3D &xhci->ports[i]; uint32_t offset =3D OFF_OPER + 0x400 + 0x10 * i; port->xhci =3D xhci; - memory_region_init_io(&port->mem, OBJECT(xhci), &xhci_port_ops, po= rt, - port->name, 0x10); + memory_region_init_io_with_dev(&port->mem, OBJECT(xhci), + &xhci_port_ops, port, + port->name, 0x10, &dev->qdev); memory_region_add_subregion(&xhci->mem, offset, &port->mem); } =20 --=20 2.17.1