Received: by 10.223.164.202 with SMTP id h10csp534898wrb; Thu, 30 Nov 2017 03:35:10 -0800 (PST) X-Google-Smtp-Source: AGs4zMZU+9j63twbVJEIxUZSJnFYmiMwe6Wo3jBa28Fw0YEOB8q/raiV2joLSCc1sMI+tKAYbjHO X-Received: by 10.101.77.9 with SMTP id i9mr2088366pgt.39.1512041710594; Thu, 30 Nov 2017 03:35:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512041710; cv=none; d=google.com; s=arc-20160816; b=Ne+/aTZMn1RDQgIjMEjejXc8uEsJpFtzJjkQaX59K0gub9+yxfcohWpompTx359SFF AXyT0/PrqOXROs9ZQo31W9zQxSPVeOjmGZ44RCgNDv3XrYRTlq50LlaRuDue6MZFDObq /9BECvDxhY+v2SojNBNF7eDdNIMnk4oijgDcwAG3DFz167dCbaGLaU9GIjJlsJ+nDSv9 dFZsDdHS3FyFXIiCpOEUAncfok6cXD2XmW6z7PzytVSfUVuPQm5oV3qi26ELr5puFdcX 5nU8TyouYxOrp5Cw2Gs9OPDschsGLImGgHHC/ydBNbDv82LElwLoMdFZKrHRKikw6+Lf 6/qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=GNvlShGs6bBn2GFronZ/juO+pUXy6/uYfeu6XqRpTOY=; b=D/goj/xety42pFzi0x6nT1h9HJObAp8688xOMoM+qCpfhYFaeV1S0E+FeF8bl5VCa/ vUw9rc4ylmRlNPNyESHDqcdRizkiTwf1g4wETdeLRVG+TOoJ+KBVgwwph+qY/so4GEqe VLs6o7lnB2MU7MHG7Lvr2Rymqmx0SV+qymRx7qeVr/ynwMMYyN6fkDKPGf5iqd8I6W1r 2fPIlEx6ezRdKpuWff3r3M0qdC1OznII3MXfcV8RBNA/TXoKSD0FYR06aM5x259gw++l +iRsc0QN15/rJpFmmr1jGN8cSzMZOShib7b2gR0ahLTQggQ3cpLNcYn2KQEe1d7qOxUK OUgA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11si2852079pgq.352.2017.11.30.03.34.57; Thu, 30 Nov 2017 03:35:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752349AbdK3Leq (ORCPT + 99 others); Thu, 30 Nov 2017 06:34:46 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:56400 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750849AbdK3Leo (ORCPT ); Thu, 30 Nov 2017 06:34:44 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAUBYUwq056928 for ; Thu, 30 Nov 2017 06:34:44 -0500 Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ejgrxt5am-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 30 Nov 2017 06:34:43 -0500 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 30 Nov 2017 11:34:42 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 30 Nov 2017 11:34:39 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAUBYdQP25755766; Thu, 30 Nov 2017 11:34:39 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D87ED11C054; Thu, 30 Nov 2017 11:29:11 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8C22611C04C; Thu, 30 Nov 2017 11:29:11 +0000 (GMT) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.145.49.184]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 30 Nov 2017 11:29:11 +0000 (GMT) From: Pierre Morel To: alex.williamson@redhat.com Cc: cohuck@redhat.com, borntraeger@de.ibm.com, zyimin@linux.vnet.ibm.com, pasic@linux.vnet.ibm.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] vfio/iommu_type1: report the IOMMU aperture info Date: Thu, 30 Nov 2017 12:34:38 +0100 X-Mailer: git-send-email 2.7.4 X-TM-AS-GCONF: 00 x-cbid: 17113011-0020-0000-0000-000003D25756 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17113011-0021-0000-0000-00004267C7A1 Message-Id: <1512041678-4563-1-git-send-email-pmorel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-30_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711300154 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When userland VFIO defines a new IOMMU for a guest it may want to specify to the guest the physical limits of the underlying host IOMMU to avoid access to forbidden memory ranges. Currently, the vfio_iommu_type1 driver does not report this information to userland. Let's extend the vfio_iommu_type1_info structure reported by the ioctl VFIO_IOMMU_GET_INFO command to report the IOMMU limits as new uint64_t entries aperture_start and aperture_end. Let's also extend the flags bit map to add a flag specifying if this extension of the info structure is reported or not. Signed-off-by: Pierre Morel --- drivers/vfio/vfio_iommu_type1.c | 42 +++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/vfio.h | 3 +++ 2 files changed, 45 insertions(+) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 8549cb1..7da5fe0 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -1526,6 +1526,40 @@ static int vfio_domains_have_iommu_cache(struct vfio_iommu *iommu) return ret; } +/** + * vfio_get_aperture - report minimal aperture of a vfio_iommu + * @iommu: the current vfio_iommu + * @start: a pointer to the aperture start + * @end : a pointer to the aperture end + * + * This function iterate on the domains using the given vfio_iommu + * and restrict the aperture to the minimal aperture common + * to all domains sharing this vfio_iommu. + */ +static void vfio_get_aperture(struct vfio_iommu *iommu, uint64_t *start, + uint64_t *end) +{ + struct iommu_domain_geometry geometry; + struct vfio_domain *domain; + + *start = 0; + *end = U64_MAX; + + mutex_lock(&iommu->lock); + /* loop on all domains using this vfio_iommu */ + list_for_each_entry(domain, &iommu->domain_list, next) { + iommu_domain_get_attr(domain->domain, DOMAIN_ATTR_GEOMETRY, + &geometry); + if (geometry.force_aperture) { + if (geometry.aperture_start > *start) + *start = geometry.aperture_start; + if (geometry.aperture_end < *end) + *end = geometry.aperture_end; + } + } + mutex_unlock(&iommu->lock); +} + static long vfio_iommu_type1_ioctl(void *iommu_data, unsigned int cmd, unsigned long arg) { @@ -1560,6 +1594,14 @@ static long vfio_iommu_type1_ioctl(void *iommu_data, info.iova_pgsizes = vfio_pgsize_bitmap(iommu); + minsz = min_t(size_t, info.argsz, sizeof(info)); + if (minsz >= offsetofend(struct vfio_iommu_type1_info, + aperture_end)) { + info.flags |= VFIO_IOMMU_INFO_APERTURE; + vfio_get_aperture(iommu, &info.aperture_start, + &info.aperture_end); + } + return copy_to_user((void __user *)arg, &info, minsz) ? -EFAULT : 0; diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 0fb25fb..780d909 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -519,6 +519,9 @@ struct vfio_iommu_type1_info { __u32 flags; #define VFIO_IOMMU_INFO_PGSIZES (1 << 0) /* supported page sizes info */ __u64 iova_pgsizes; /* Bitmap of supported page sizes */ +#define VFIO_IOMMU_INFO_APERTURE (1 << 1) /* supported aperture info */ + __u64 aperture_start; /* start of DMA aperture */ + __u64 aperture_end; /* end of DMA aperture */ }; #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12) -- 2.7.4 From 1585613801185203351@xxx Fri Dec 01 20:12:37 +0000 2017 X-GM-THRID: 1585613801185203351 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread