From patchwork Mon Feb 20 01:28:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 9581919 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4141E604A0 for ; Mon, 20 Feb 2017 01:38:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 370ED28835 for ; Mon, 20 Feb 2017 01:38:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 28E6D2883F; Mon, 20 Feb 2017 01:38:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B0C7328835 for ; Mon, 20 Feb 2017 01:38:48 +0000 (UTC) Received: from localhost ([::1]:35651 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cfcwB-0001Yb-Pt for patchwork-qemu-devel@patchwork.kernel.org; Sun, 19 Feb 2017 20:38:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cfcsw-0007qi-7b for qemu-devel@nongnu.org; Sun, 19 Feb 2017 20:35:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cfcsr-0007rk-Ah for qemu-devel@nongnu.org; Sun, 19 Feb 2017 20:35:26 -0500 Received: from mga05.intel.com ([192.55.52.43]:8331) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cfcsr-0007rK-1I for qemu-devel@nongnu.org; Sun, 19 Feb 2017 20:35:21 -0500 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP; 19 Feb 2017 17:35:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,184,1484035200"; d="scan'208";a="60301301" Received: from lantianyu-ws.sh.intel.com (HELO localhost) ([10.239.159.159]) by orsmga004.jf.intel.com with ESMTP; 19 Feb 2017 17:35:17 -0800 From: Lan Tianyu To: qemu-devel@nongnu.org Date: Mon, 20 Feb 2017 09:28:06 +0800 Message-Id: <1487554087-15347-4-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1487554087-15347-1-git-send-email-tianyu.lan@intel.com> References: <1487554087-15347-1-git-send-email-tianyu.lan@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.43 Subject: [Qemu-devel] [Resend RFC PATCH 3/4] Intel iommu: Add Intel IOMMU fault event callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lan Tianyu , kevin.tian@intel.com, yi.l.liu@intel.com, mst@redhat.com, jan.kiszka@siemens.com, jasowang@redhat.com, peterx@redhat.com, alex.williamson@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch is to deal with fault event reported from IOMMU driver. Signed-off-by: Lan Tianyu --- hw/i386/intel_iommu.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 9b1ba1b..79507d2 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2286,6 +2286,30 @@ static void vtd_iommu_notify_flag_changed(MemoryRegion *iommu, } } +static void vtd_iommu_notify_fault_event(MemoryRegion *iommu, + IOMMUFaultInfo *info) +{ + VTDAddressSpace *vtd_as = container_of(iommu, VTDAddressSpace, iommu); + IntelIOMMUState *s = vtd_as->iommu_state; + bool is_fpd_set = false; + uint8_t bus_num = pci_bus_num(vtd_as->bus); + uint8_t devfn = vtd_as->devfn; + VTDContextEntry ce; + + /* Replace source id with device's vbdf */ + info->sid = vtd_make_source_id(bus_num, devfn); + + if (!vtd_dev_to_context_entry(s, bus_num, devfn, &ce)) { + is_fpd_set = ce.lo & VTD_CONTEXT_ENTRY_FPD; + if (is_fpd_set) { + trace_vtd_fault_disabled(); + } else { + vtd_report_dmar_fault(s, info->sid, info->addr, + info->fault_reason, info->is_write); + } + } +} + static const VMStateDescription vtd_vmstate = { .name = "iommu-intel", .version_id = 1, @@ -2816,6 +2840,7 @@ static void vtd_init(IntelIOMMUState *s) s->iommu_ops.translate = vtd_iommu_translate; s->iommu_ops.notify_flag_changed = vtd_iommu_notify_flag_changed; + s->iommu_ops.notify_fault_event = vtd_iommu_notify_fault_event; s->iommu_ops.replay = vtd_iommu_replay; s->root = 0; s->root_extended = false;