Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1135085imu; Wed, 16 Jan 2019 13:23:05 -0800 (PST) X-Google-Smtp-Source: ALg8bN78BS+4D9zFS5rkyuHgHUvQ5ZFkDSTM/K7hYeLsxeMFk/Zf69ROpAs3pJd0cGd+d69h4iJh X-Received: by 2002:a17:902:8d8e:: with SMTP id v14mr11900754plo.133.1547673785638; Wed, 16 Jan 2019 13:23:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547673785; cv=none; d=google.com; s=arc-20160816; b=ExGq5hqE43Iq84bvJzecwh9uplDHP3MRSbvgtrPUL7BlwjBWKyWfbNYVC8KbY83ftV x67Jga2XphdPOoRh4gLaJcL2QEvL4vWNneSoY3X9vH3Zn+L6M4eV0KHPQYSE61nIsqgL RIKqKoBF7GFbr+Wo0QhJPvDx84KlAiDoYMcR7FM4ymXGAWUi2LA0yHmLGzELKyB/Cx1m 29hUhlSVVFq8z2+E74yO1BodnG2RMDnN44i1k9gFpIh/20aXuhzf97kB7/aLRD4IketX WRBnQUvKw0288k8nS9IWayfnokxzrsV+V9H++BW6ab/ziQjujWWZDRmM48zHEuBrjiTp 1vSg== 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:reply-to; bh=L5iGjmPdGdxDsHTFbRg0Dxrp2CdZri3Py5r4xdt7ny0=; b=uHj6iw97P0F376n5OSmUWZZ6KlvmMNejTTJryrpBGX1DwspL0WEkPt6YE1+X/LFj+7 992Z0WMNfGS372w4ZLK3RvtzPyiDgHqY49E+kjlquB93WBSlMIgkA8/ouJPkLdWVD1Um NldnZU+Yb/sJSLdeiJ+LoReYvvIhMvI2ekZ3D2LSnXfxuJuXxI7yzfXlOcgFGUVuf4ed 8NjpM8gmt45SrpuIFNjMe14lRyY9mWU2+Wham4NkWsWxlX5oq8fiDPJvm3JN2XKdxBDd +U1c/Buq3PaM7axXMIFDg9+Jv00uGbejflgOW0K7HxI8LdHfbFibSA0X0g0iEguGS/wT kTXg== 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 p5si7417371pfb.188.2019.01.16.13.22.47; Wed, 16 Jan 2019 13:23:05 -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 S2388902AbfAPJeB (ORCPT + 99 others); Wed, 16 Jan 2019 04:34:01 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:60536 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388767AbfAPJeA (ORCPT ); Wed, 16 Jan 2019 04:34:00 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id x0G9OF5U110238 for ; Wed, 16 Jan 2019 04:33:59 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2q1ytjepgp-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 16 Jan 2019 04:33:59 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 16 Jan 2019 09:33:57 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 16 Jan 2019 09:33:54 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x0G9XrAc50659582 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 16 Jan 2019 09:33:53 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 57F3C11C04A; Wed, 16 Jan 2019 09:33:53 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D51E511C050; Wed, 16 Jan 2019 09:33:52 +0000 (GMT) Received: from [9.152.224.140] (unknown [9.152.224.140]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 16 Jan 2019 09:33:52 +0000 (GMT) Reply-To: pmorel@linux.ibm.com Subject: Re: [PATCH v1] iommu/s390: Declare s390 iommu reserved regions To: Gerald Schaefer Cc: joro@8bytes.org, linux-s390@vger.kernel.org, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, alex.williamson@redhat.com, shameerali.kolothum.thodi@huawei.com, walling@linux.ibm.com References: <1547573850-9459-1-git-send-email-pmorel@linux.ibm.com> <1547573850-9459-2-git-send-email-pmorel@linux.ibm.com> <20190115203335.111bfcdc@thinkpad> From: Pierre Morel Date: Wed, 16 Jan 2019 10:33:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20190115203335.111bfcdc@thinkpad> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 19011609-0012-0000-0000-000002E8B5D0 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19011609-0013-0000-0000-0000211FCCFB Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-01-16_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 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901160080 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15/01/2019 20:33, Gerald Schaefer wrote: > On Tue, 15 Jan 2019 18:37:30 +0100 > Pierre Morel wrote: > >> The s390 iommu can only allow DMA transactions between the zPCI device >> entries start_dma and end_dma. >> >> Let's declare the regions before start_dma and after end_dma as >> reserved regions using the appropriate callback in iommu_ops. >> >> Signed-off-by: Pierre Morel >> --- >> drivers/iommu/s390-iommu.c | 29 +++++++++++++++++++++++++++++ >> 1 file changed, 29 insertions(+) >> >> diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c >> index 22d4db3..5ca91a1 100644 >> --- a/drivers/iommu/s390-iommu.c >> +++ b/drivers/iommu/s390-iommu.c >> @@ -363,6 +363,33 @@ void zpci_destroy_iommu(struct zpci_dev *zdev) >> iommu_device_sysfs_remove(&zdev->iommu_dev); >> } >> >> +static void s390_get_resv_regions(struct device *dev, struct list_head *head) >> +{ >> + struct iommu_resv_region *region; >> + struct zpci_dev *zdev = to_pci_dev(dev)->sysdata; >> + >> + region = iommu_alloc_resv_region(0, zdev->start_dma, >> + 0, IOMMU_RESV_RESERVED); >> + if (!region) >> + return; >> + list_add_tail(®ion->list, head); >> + >> + region = iommu_alloc_resv_region(zdev->end_dma + 1, >> + ~0UL - zdev->end_dma, >> + 0, IOMMU_RESV_RESERVED); > > Can you guarantee that start_dma will never be 0 and end_dma never ~0UL, > even with future HW? > > In any of these cases, your code would reserve strange ranges, and sysfs > would report broken reserved ranges. > > Maybe add a check for start_dma > 0 and end_dma < ULONG_MAX? Yes, thanks. > >> + if (!region) >> + return; >> + list_add_tail(®ion->list, head); >> +} >> + >> +static void s390_put_resv_regions(struct device *dev, struct list_head *head) >> +{ >> + struct iommu_resv_region *entry, *next; >> + >> + list_for_each_entry_safe(entry, next, head, list) >> + kfree(entry); >> +} > > It looks very wrong that there is no matching list_del() for the previous > list_add_tail(). However, it seems to be done like this everywhere else, > and the calling functions (currently) only use temporary list_heads as > far as I can see, so I guess it should be OK (for now). > > Still, a list_del() would be nice :-) hum. right. > >> + >> static const struct iommu_ops s390_iommu_ops = { >> .capable = s390_iommu_capable, >> .domain_alloc = s390_domain_alloc, >> @@ -376,6 +403,8 @@ static const struct iommu_ops s390_iommu_ops = { >> .remove_device = s390_iommu_remove_device, >> .device_group = generic_device_group, >> .pgsize_bitmap = S390_IOMMU_PGSIZES, >> + .get_resv_regions = s390_get_resv_regions, >> + .put_resv_regions = s390_put_resv_regions, >> }; >> >> static int __init s390_iommu_init(void) > > With the start/end_dma issue addressed (if necessary): > Acked-by: Gerald Schaefer > Thanks. Regards, Pierre -- Pierre Morel Linux/KVM/QEMU in Böblingen - Germany