Received: by 10.223.164.202 with SMTP id h10csp12086wrb; Thu, 30 Nov 2017 06:19:14 -0800 (PST) X-Google-Smtp-Source: AGs4zMZSElorjo0chDIXDapwg6kSYUML+Al9rO7etY98Duv3CB88zkPK4dTQVh0Kh+qzaDLVA5Xj X-Received: by 10.84.240.131 with SMTP id z3mr2816304plk.317.1512051554801; Thu, 30 Nov 2017 06:19:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512051554; cv=none; d=google.com; s=arc-20160816; b=UBLUeaCaT92DympXzfd/KAl+Jh/W6IDViMUtigFq+9r+ixjtpZnbs9Qpf2wG64xEo+ I5SrCR9O+1LE3lCfBb+Nd8ZIm5R16yXAymdz55/4G1N9bYYwcilT9zvfTKHcQx4uCtIZ eBHjdDmG1SFbwQMUzSEUXWylsZhhEapt3O6jsgZaIBx5AhKqxj5twCHMJ2bswzCaiUVg 5gi2by0k1eSFHlEFg/dIlXVnXUjLn//Rjnz9OGIx2rLZ1KM4sVUgXAsrjnI9CsxcdOrI kW+P1Wa/fy95kWmiGULNpchh0WenrXD71ly88UHqlphNCYVuhJApF5bX2qKnTQPbFhJO VL+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date:from :references:cc:to:subject:arc-authentication-results; bh=OYt1+YerTEDdbigoocvroj/SDrKNWagaNh5sh3h9am4=; b=p0x24j49MbxJ18LQQUONB6CgBFdqSUWfsc6VJJft1VT8ZoqZSWcAJjNZvZ7do2jwSm 5gzVa0wSakSbvJBlIq4h9H1yXBDksUCvPdLbwKQKpfF8iivDAOhexoy4z9VFUFNYLfgS AzoVLM6EVRe4C+Z3d5O8hmrvBLARQnKs+LPfHSdd+oJB57QkesFoOznKmjcFoURQ9NeC 4NjIYq5/Lo0gEy6nKPxYvrJjn+9SXTKRyVOoeQWUzZLs3JPn37KFGbtufYLMIsKzg7DB 4SuXR5oVBFOTI7z1+kaOzS6uEDpNlLSzWGhvf6zEiN/xiZ9WbL44HCrKsLa+kHm5DZUD gAqQ== 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 m89si3280431pfg.140.2017.11.30.06.19.00; Thu, 30 Nov 2017 06:19:14 -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 S1752427AbdK3ORt (ORCPT + 99 others); Thu, 30 Nov 2017 09:17:49 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:59062 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751810AbdK3ORs (ORCPT ); Thu, 30 Nov 2017 09:17:48 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAUEHcAe147162 for ; Thu, 30 Nov 2017 09:17:47 -0500 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ejkkf857v-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 30 Nov 2017 09:17:46 -0500 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 30 Nov 2017 14:17:41 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 30 Nov 2017 14:17:38 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAUEHbCc31850556; Thu, 30 Nov 2017 14:17:37 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2616EAE057; Thu, 30 Nov 2017 14:10:43 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B3DEBAE056; Thu, 30 Nov 2017 14:10:42 +0000 (GMT) Received: from [9.145.49.184] (unknown [9.145.49.184]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 30 Nov 2017 14:10:42 +0000 (GMT) Subject: Re: [PATCH] vfio/iommu_type1: report the IOMMU aperture info To: Auger Eric , 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 References: <1512041678-4563-1-git-send-email-pmorel@linux.vnet.ibm.com> <5c434d35-70eb-2d2b-4efa-b9a072e973a6@redhat.com> From: Pierre Morel Date: Thu, 30 Nov 2017 15:17:36 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <5c434d35-70eb-2d2b-4efa-b9a072e973a6@redhat.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 17113014-0012-0000-0000-000005936266 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17113014-0013-0000-0000-0000190E51CA Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-30_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711300187 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 30/11/2017 14:22, Auger Eric wrote: > Hi Pierre, > On 30/11/17 12:34, Pierre Morel wrote: >> 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) >> > > In the past I was told by Alex that using the capability chain > extensions to add some new capabilities was a better approach: > > https://lkml.org/lkml/2016/4/6/751 > > I did that kind of exercise in > [PATCH v9 7/7] vfio/type1: return MSI geometry through > VFIO_IOMMU_GET_INFO capability chains > > https://lists.linuxfoundation.org/pipermail/iommu/2016-May/016892.html > > The patch was not used eventually but maybe that can help. > > Thanks > > Eric > indeed interesting, I will go this way. Thanks and also thanks for the pointers. Pierre -- Pierre Morel Linux/KVM/QEMU in B�blingen - Germany From 1585500835001336939@xxx Thu Nov 30 14:17:04 +0000 2017 X-GM-THRID: 1585490648319889089 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread