From patchwork Mon Mar 2 16:58:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baptiste Reynal X-Patchwork-Id: 5915821 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 7A5AF9F380 for ; Mon, 2 Mar 2015 17:11:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AEF8520211 for ; Mon, 2 Mar 2015 17:11:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C6705201F2 for ; Mon, 2 Mar 2015 17:11:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755374AbbCBRLA (ORCPT ); Mon, 2 Mar 2015 12:11:00 -0500 Received: from mail-wg0-f52.google.com ([74.125.82.52]:41246 "EHLO mail-wg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755744AbbCBQ73 (ORCPT ); Mon, 2 Mar 2015 11:59:29 -0500 Received: by wghl18 with SMTP id l18so34709231wgh.8 for ; Mon, 02 Mar 2015 08:59:28 -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=jdyHTPA1B4zS6WCvCQIU7W+1qSE8GoWFOxn/pei3eFQ=; b=LU6sQtWJnM0ad65rrXI73KFHNt/7KCz/R+Tl6+2K/S+Y4bZ+efKlfYgsrVIdGVc/QY W5GQxi5k3ro28o/qng+1ST0ZChlvNrZPUkNUVKzSwGbNNxRNFiLq7XNvwoS3EZ0+fu/A 2ogMpcgPA83v8oSCQna4EPmWRV+N92uDeGVvC6KN9cmBI9bNRvX143P3EN07M9gKL4Ju Av+xW9KHQ6Jj8Cf1c4otnerTX6vUgqLuFLT8hCOgMpQnF8uGAW5cii5tDJc7eZbMzklD 2/HuzX2aqzLCfNVf1lWURR71qwKDp031WBAXZbpmiwbpHHjH4wqM4/NzNXUv2nwwgZas X00w== X-Gm-Message-State: ALoCoQm2gKZC94rPowUhSV77Hs3qnklPsgouIWqEDGNaIzYmqMUDZt6WrK7zWCaGlD/pheY/P8UJ X-Received: by 10.194.71.175 with SMTP id w15mr58889079wju.16.1425315567667; Mon, 02 Mar 2015 08:59:27 -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 dj5sm20027898wjb.28.2015.03.02.08.59.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Mar 2015 08:59:27 -0800 (PST) From: Baptiste Reynal To: iommu@lists.linux-foundation.org, kvmarm@lists.cs.columbia.edu Cc: tech@virtualopensystems.com, Antonios Motakis , Baptiste Reynal , Alex Williamson , kvm@vger.kernel.org (open list:VFIO DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 4/5] vfio: type1: replace vfio_domains_have_iommu_cache with generic function Date: Mon, 2 Mar 2015 17:58:26 +0100 Message-Id: <1425315507-29661-5-git-send-email-b.reynal@virtualopensystems.com> X-Mailer: git-send-email 2.3.1 In-Reply-To: <1425315507-29661-1-git-send-email-b.reynal@virtualopensystems.com> References: <1425315507-29661-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 998619b..0ea371b 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->caps & 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 @@ -948,23 +965,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->caps & IOMMU_CAP_CACHE_COHERENCY)) { - ret = 0; - break; - } - } - mutex_unlock(&iommu->lock); - - return ret; -} - static long vfio_iommu_type1_ioctl(void *iommu_data, unsigned int cmd, unsigned long arg) { @@ -980,7 +980,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; }