From patchwork Sun Feb 19 14:47:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 9581619 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 1C47F6057F for ; Sun, 19 Feb 2017 14:54:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02E10286CB for ; Sun, 19 Feb 2017 14:54:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E88E3286F0; Sun, 19 Feb 2017 14:54:12 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 912CB286F0 for ; Sun, 19 Feb 2017 14:54:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751571AbdBSOyK (ORCPT ); Sun, 19 Feb 2017 09:54:10 -0500 Received: from mga11.intel.com ([192.55.52.93]:14436 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751593AbdBSOyI (ORCPT ); Sun, 19 Feb 2017 09:54:08 -0500 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Feb 2017 06:54:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,181,1484035200"; d="scan'208";a="67684445" Received: from lantianyu-ws.sh.intel.com (HELO localhost) ([10.239.159.159]) by fmsmga006.fm.intel.com with ESMTP; 19 Feb 2017 06:54:05 -0800 From: Lan Tianyu To: kvm@vger.kernel.org Cc: Lan Tianyu , kevin.tian@intel.com, mst@redhat.com, jan.kiszka@siemens.com, jasowang@redhat.com, peterx@redhat.com, david@gibson.dropbear.id.au, alex.williamson@redhat.com, yi.l.liu@intel.com Subject: [RFC PATCH 3/3] VFIO: Add new cmd for user space to get IOMMU fault info Date: Sun, 19 Feb 2017 22:47:09 +0800 Message-Id: <1487515629-13815-4-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1487515629-13815-1-git-send-email-tianyu.lan@intel.com> References: <1487515629-13815-1-git-send-email-tianyu.lan@intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch is to introduce cmd VFIO_IOMMU_GET_FAULT_INFO cmd to return fault info reported by IOMMU driver. Signed-off-by: Lan Tianyu --- drivers/vfio/vfio_iommu_type1.c | 31 +++++++++++++++++++++++++++++++ include/uapi/linux/vfio.h | 15 +++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index dc434a3..58e6689 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -1657,6 +1657,37 @@ static long vfio_iommu_type1_ioctl(void *iommu_data, mutex_unlock(&iommu->fault_lock); return ret; + } else if (cmd == VFIO_IOMMU_GET_FAULT_INFO) { + struct vfio_iommu_type1_get_fault_info info; + int fault_size = sizeof(struct vfio_iommu_fault_info); + int ret; + + minsz = offsetofend(struct vfio_iommu_type1_get_fault_info, + count); + if (copy_from_user(&info, (void __user *)arg, minsz)) + return -EFAULT; + + if (info.argsz < minsz) + return -EINVAL; + + mutex_lock(&iommu->fault_lock); + info.count = iommu->fault_count; + + if (info.argsz < sizeof(info) + + iommu->fault_count * fault_size) + ret = -ENOSPC; + + if (copy_to_user((void __user *)arg, &info, minsz)) + ret = -EFAULT; + + if (!ret & !copy_to_user((void __user *)(arg + minsz), + iommu->fault_info, info.count * fault_size)) + iommu->fault_count = 0; + else if (ret != ENOSPC) + ret = -EFAULT; + + mutex_unlock(&iommu->fault_lock); + return ret; } return -ENOTTY; diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index da359dd..e6fd86f 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -562,6 +562,11 @@ struct vfio_iommu_type1_set_fault_eventfd { #define VFIO_IOMMU_SET_FAULT_EVENTFD _IO(VFIO_TYPE, VFIO_BASE + 17) +/* + * VFIO_IOMMU_GET_FAULT_INFO _IO(VFIO_TYPE, VFIO_BASE + 18) + * + * Return IOMMU fault info to userspace. + */ struct vfio_iommu_fault_info { __u64 addr; __u16 sid; @@ -569,6 +574,16 @@ struct vfio_iommu_fault_info { __u8 is_write:1; }; +struct vfio_iommu_type1_get_fault_info { + __u32 argsz; + __u32 flags; + __u32 count; + struct vfio_iommu_fault_info fault_info[]; +}; + +#define VFIO_IOMMU_GET_FAULT_INFO _IO(VFIO_TYPE, VFIO_BASE + 18) + + /* -------- Additional API for SPAPR TCE (Server POWERPC) IOMMU -------- */ /*