Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp3037670pxy; Wed, 4 Aug 2021 00:12:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwt4CRXJruEAWDD39kaD4CSQQwCPpOZbzVS8UdkX7cngY/ahyG4cO3H59tdOzuPky59jZ3g X-Received: by 2002:a05:6402:7da:: with SMTP id u26mr30746625edy.270.1628061121905; Wed, 04 Aug 2021 00:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628061121; cv=none; d=google.com; s=arc-20160816; b=LA8gazBWzKaTHWGMw6/ktIGXHXu8zyHUvNjk9yn40cVBx1RGvfpvVtHQhz9aCKS4P2 WONpOVS+D3uhHI07VjYbUzcGiZiBC1vjBdx3qsy5Trptr3Sia56Y0CYEvwNylssNYbR8 p5i1N5dWQRWr5uUFzWAA0kfSLrrRC9wKBiuoCrUzOLK0s0VHqo2HnECoXQj4A22zxkrB lqjC5CMqZI6cs4p0ScLXuKV1a+NmagftOLlyFy5LeLMAk5snYdimIsDQg2LK+QTFFrlR Ztb0fvS2J/Vp1uSe+jOd7Ce7O4eEX5vjzF6xISNSatheFoLCSdKD5pOect3AQOFVL6js wjCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature:dkim-filter; bh=V/XYsXsYVsA5Pb1ntrRBOWS6XD7DTF+fjpdIcug4aCw=; b=IHNFvoMZhTWRhWA3LrhIbRaqjY6vYVnT0ZIunI77OcaWLOPQ1BXjfQT5cUj/vGk+8y PraWKh+a+1Rq4h1wbQOIi97GsrFtoeW24hACUx5djf4VzAaFRhsqSWhCq5G+pLQWIFjB ITFTFYVZmO/FOWz4Cd5J4U8yaPKhWwIh+q4HJwCuCNmJndt40cYG/f75kmx7WDcxCO1M +GkWegVwt8T2IxwubADU8LTJ1czOfq/LLgrUjPo0pMC7sZ1XPJ5B4OtZuNFJrKVM5hB4 HzJ/ZQWa218cBWd5pkoPuewTXiVI5LwWpRdSmGTvxGgO1WM7VdJsTdqh0myo6ghTzyzz G8+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Cj5PvOhj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q9si1378297edw.143.2021.08.04.00.11.38; Wed, 04 Aug 2021 00:12:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Cj5PvOhj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235643AbhHDGoB (ORCPT + 99 others); Wed, 4 Aug 2021 02:44:01 -0400 Received: from linux.microsoft.com ([13.77.154.182]:37274 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235070AbhHDGoA (ORCPT ); Wed, 4 Aug 2021 02:44:00 -0400 Received: from [192.168.1.87] (unknown [223.178.56.171]) by linux.microsoft.com (Postfix) with ESMTPSA id DADCE209DD4A; Tue, 3 Aug 2021 23:43:44 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DADCE209DD4A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1628059428; bh=V/XYsXsYVsA5Pb1ntrRBOWS6XD7DTF+fjpdIcug4aCw=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=Cj5PvOhjHeKFOHz1X1tSzo8ZfZqL0lX6n3/1G8fOiix2DXh/xdkddfTDhgC8RMhHF TmcseRM1Soe4Rl5V4AwJe3G+VYxGCWd+m1OGKZE0eu9IuOOMnhjHFjyw8iJh8rv0ZE oey+Badv593cyQMjtl0kxCnP/vyJ2Cb6aAGXneHo= Subject: Re: [RFC v1 5/8] mshv: add paravirtualized IOMMU support To: Wei Liu Cc: Linux on Hyper-V List , virtualization@lists.linux-foundation.org, Linux Kernel List , Michael Kelley , Vineeth Pillai , Sunil Muthuswamy , Nuno Das Neves , pasha.tatashin@soleen.com, Joerg Roedel , Will Deacon , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Dexuan Cui , "open list:IOMMU DRIVERS" References: <20210709114339.3467637-1-wei.liu@kernel.org> <20210709114339.3467637-6-wei.liu@kernel.org> <77670985-2a1b-7bbd-2ede-4b7810c3e220@linux.microsoft.com> <20210803214718.hnp3ejs35lh455fw@liuwe-devbox-debian-v2> From: Praveen Kumar Message-ID: <562f4c31-1ea5-ea56-ac0a-6bd80b61c3df@linux.microsoft.com> Date: Wed, 4 Aug 2021 12:13:42 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210803214718.hnp3ejs35lh455fw@liuwe-devbox-debian-v2> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04-08-2021 03:17, Wei Liu wrote: >>> +static size_t hv_iommu_unmap(struct iommu_domain *d, unsigned long iova, >>> + size_t size, struct iommu_iotlb_gather *gather) >>> +{ >>> + size_t unmapped; >>> + struct hv_iommu_domain *domain = to_hv_iommu_domain(d); >>> + unsigned long flags, npages; >>> + struct hv_input_unmap_device_gpa_pages *input; >>> + u64 status; >>> + >>> + unmapped = hv_iommu_del_mappings(domain, iova, size); >>> + if (unmapped < size) >>> + return 0; >> Is there a case where unmapped > 0 && unmapped < size ? >> > There could be such a case -- hv_iommu_del_mappings' return value is >= 0. > Is there a problem with this predicate? What I understand, if we are unmapping and return 0, means nothing was unmapped, and will that not cause any corruption or illegal access of unmapped memory later? From __iommu_unmap ... 13 while (unmapped < size) { 12 size_t pgsize = iommu_pgsize(domain, iova, size - unmapped); 11 10 unmapped_page = ops->unmap(domain, iova, pgsize, iotlb_gather); 9 if (!unmapped_page) 8 break; <<< we just break here, thinking there is nothing unmapped, but actually hv_iommu_del_mappings has removed some pages. 7 6 pr_debug("unmapped: iova 0x%lx size 0x%zx\n", 5 ¦iova, unmapped_page); 4 3 iova += unmapped_page; 2 unmapped += unmapped_page; 1 } ... Am I missing something ? Regards, ~Praveen.