From patchwork Wed Sep 4 13:28:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11130277 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5041A14DE for ; Wed, 4 Sep 2019 13:29:25 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3657622CEA for ; Wed, 4 Sep 2019 13:29:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3657622CEA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i5VKS-0001Zm-4T; Wed, 04 Sep 2019 13:28:08 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i5VKR-0001ZR-01 for xen-devel@lists.xenproject.org; Wed, 04 Sep 2019 13:28:07 +0000 X-Inumbo-ID: d35957b8-cf17-11e9-abb6-12813bfff9fa Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id d35957b8-cf17-11e9-abb6-12813bfff9fa; Wed, 04 Sep 2019 13:28:05 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 93F93B0E5; Wed, 4 Sep 2019 13:28:04 +0000 (UTC) From: Jan Beulich To: "xen-devel@lists.xenproject.org" References: <050de29e-5a10-8b4a-44f1-0241f4b33ee2@suse.com> Message-ID: <959e3395-4637-6e9b-74dc-9982acf10dec@suse.com> Date: Wed, 4 Sep 2019 15:28:10 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <050de29e-5a10-8b4a-44f1-0241f4b33ee2@suse.com> Content-Language: en-US Subject: [Xen-devel] [PATCH 3/3] VT-d/ATS: tidy device_in_domain() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Tian Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Use appropriate types. Drop unnecessary casts. Check for failures which can (at least in theory because of non-obvious breakage elsewhere) occur, instead of ones which really can't (map_domain_page() won't return NULL). Signed-off-by: Jan Beulich Reviewed-by: Kevin Tian --- a/xen/drivers/passthrough/vtd/x86/ats.c +++ b/xen/drivers/passthrough/vtd/x86/ats.c @@ -71,23 +71,25 @@ int ats_device(const struct pci_dev *pde return pos; } -static int device_in_domain(const struct iommu *iommu, - const struct pci_dev *pdev, u16 did) +static bool device_in_domain(const struct iommu *iommu, + const struct pci_dev *pdev, uint16_t did) { - struct root_entry *root_entry = NULL; + struct root_entry *root_entry; struct context_entry *ctxt_entry = NULL; - int tt, found = 0; + unsigned int tt; + bool found = false; - root_entry = (struct root_entry *) map_vtd_domain_page(iommu->root_maddr); - if ( !root_entry || !root_present(root_entry[pdev->bus]) ) - goto out; - - ctxt_entry = (struct context_entry *) - map_vtd_domain_page(root_entry[pdev->bus].val); + if ( unlikely(!iommu->root_maddr) ) + { + ASSERT_UNREACHABLE(); + return false; + } - if ( ctxt_entry == NULL ) + root_entry = map_vtd_domain_page(iommu->root_maddr); + if ( !root_present(root_entry[pdev->bus]) ) goto out; + ctxt_entry = map_vtd_domain_page(root_entry[pdev->bus].val); if ( context_domain_id(ctxt_entry[pdev->devfn]) != did ) goto out; @@ -95,7 +97,7 @@ static int device_in_domain(const struct if ( tt != CONTEXT_TT_DEV_IOTLB ) goto out; - found = 1; + found = true; out: if ( root_entry ) unmap_vtd_domain_page(root_entry);