From patchwork Wed Mar 4 16:07:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baptiste Reynal X-Patchwork-Id: 5937501 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 517CE9F36A for ; Wed, 4 Mar 2015 16:09:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D6981202AE for ; Wed, 4 Mar 2015 16:09:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C242820272 for ; Wed, 4 Mar 2015 16:09:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759126AbbCDQIs (ORCPT ); Wed, 4 Mar 2015 11:08:48 -0500 Received: from mail-wi0-f169.google.com ([209.85.212.169]:45433 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758992AbbCDQIp (ORCPT ); Wed, 4 Mar 2015 11:08:45 -0500 Received: by wibbs8 with SMTP id bs8so410763wib.4 for ; Wed, 04 Mar 2015 08:08:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kEfIeOSDY/CGDrikUCbmBTh3JbUyPGJTv71MX0K5fQc=; b=VJfpnIZkUmhwrYDkfb7BbZrUmroTYRcuCMpMqHfVTf1rhKIxj9zUSb26UBB2VeOhuT XvnqTfFGw6gXmwZjdya4xnHk0UOqoS0dk75EcRjNtmGRZgT1rR/0e4izOboynAdHvs2i PyX86tVA1cdPz18fOwGkjEfmdCqa2rWJ08RIhx15KE692325ObW9YvWCBDtBLdCKp8/P cquuJw5miN7m9Lehp3lmT26BnCRGxezKxavpmhevsc8qLC3lgRZGmcIxYPsNbWz6afat EsoQtoTZZlSYBhgZOoBYytXrA8Slcro7V/TIntadsICoQCUbb66tKZiGRm3ZVsunPxjI Skqw== X-Gm-Message-State: ALoCoQkBSvVp4fsZcSQ/9AoVC1ETSHSz9Q+yGqzTeCvQuop4s3iZDHpzzGhkSjZn5d+5/aayGhNH X-Received: by 10.180.89.238 with SMTP id br14mr14534159wib.68.1425485324776; Wed, 04 Mar 2015 08:08:44 -0800 (PST) Received: from localhost (LPuteaux-656-1-278-113.w80-15.abo.wanadoo.fr. [80.15.154.113]) by mx.google.com with ESMTPSA id hi6sm6555504wjc.34.2015.03.04.08.08.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Mar 2015 08:08:44 -0800 (PST) From: Baptiste Reynal To: iommu@lists.linux-foundation.org, kvmarm@lists.cs.columbia.edu Cc: eric.auger@linaro.org, alex.williamson@redhat.com, tech@virtualopensystems.com, Antonios Motakis , Baptiste Reynal , kvm@vger.kernel.org (open list:VFIO DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v5 3/4] vfio: type1: replace vfio_domains_have_iommu_cache with generic function Date: Wed, 4 Mar 2015 17:07:53 +0100 Message-Id: <1425485274-5709-4-git-send-email-b.reynal@virtualopensystems.com> X-Mailer: git-send-email 2.3.1 In-Reply-To: <1425485274-5709-1-git-send-email-b.reynal@virtualopensystems.com> References: <1425485274-5709-1-git-send-email-b.reynal@virtualopensystems.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Antonios Motakis Replace the function vfio_domains_have_iommu_cache() with a more generic function vfio_domains_have_iommu_cap() which allows to check all domains of an vfio_iommu structure for a given cached capability. Signed-off-by: Antonios Motakis Signed-off-by: Baptiste Reynal --- drivers/vfio/vfio_iommu_type1.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 57d8c37..a5847e8 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -82,6 +82,23 @@ struct vfio_group { struct list_head next; }; +static int vfio_domains_have_iommu_cap(struct vfio_iommu *iommu, int cap) +{ + struct vfio_domain *domain; + int ret = 1; + + mutex_lock(&iommu->lock); + list_for_each_entry(domain, &iommu->domain_list, next) { + if (!(domain->domain->ops->capable(cap))) { + ret = 0; + break; + } + } + mutex_unlock(&iommu->lock); + + return ret; +} + /* * This code handles mapping and unmapping of user data buffers * into DMA'ble space using the IOMMU @@ -935,23 +952,6 @@ static void vfio_iommu_type1_release(void *iommu_data) kfree(iommu); } -static int vfio_domains_have_iommu_cache(struct vfio_iommu *iommu) -{ - struct vfio_domain *domain; - int ret = 1; - - mutex_lock(&iommu->lock); - list_for_each_entry(domain, &iommu->domain_list, next) { - if (!(domain->prot & IOMMU_CACHE)) { - ret = 0; - break; - } - } - mutex_unlock(&iommu->lock); - - return ret; -} - static long vfio_iommu_type1_ioctl(void *iommu_data, unsigned int cmd, unsigned long arg) { @@ -967,7 +967,8 @@ static long vfio_iommu_type1_ioctl(void *iommu_data, case VFIO_DMA_CC_IOMMU: if (!iommu) return 0; - return vfio_domains_have_iommu_cache(iommu); + return vfio_domains_have_iommu_cap(iommu, + IOMMU_CAP_CACHE_COHERENCY); default: return 0; }