Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3702714pxt; Tue, 10 Aug 2021 09:23:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5fS6ouAb4D9tHQyr9BSKBdBuOIZsOMqxqjto4sCZ0oEjTzp6BXB9fUD1G8AClmF+UBsWy X-Received: by 2002:a05:6602:2253:: with SMTP id o19mr442089ioo.198.1628612624255; Tue, 10 Aug 2021 09:23:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628612624; cv=none; d=google.com; s=arc-20160816; b=rJ4hmddEH+P7bc9ENhrsrJlsHLdY9NfnoBCPjQtqzXCY9OdozrUJD+4cJsBmSHMPhd 6r8ewJNS8dvMP0DqttlHc/XPqFxbG8GVitJx6yPuXPGUXZn8MDvFNLkB+mjUTFngpXBJ jAqHM1I2vHToioBcnqP1qyB/JWHNVRtFU8SiUS07ASmb2gTNMthJHMf9XPO/mGRnQHzF 8x6rZgp43Y0ItIyf69pQkNPFb5J10zgadMsspi5xL43A7p4LEoS1w9fGw10QwFax/u/y 932NiJrsM9KV9P9fXZJstDpmTYMtVwtBXPbR1aHHd9LMWjQrmIWX20x+yVpfaT6zf7m8 /eDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=P7tG0VICffIvt3SyEoitjgLNgYWI+9vAdgdbLXyUgnA=; b=kw/lNXyYyQZQvBaQUDlq/PS7cpFrn7nxX8j2ONDSBxgWHzviAkqTlPdT+8TR/M1rJA FhTAi7k48RCxLs/16SC2xqa4QhtH+RiuT0lnX7hSncVw/K0PccCC/ZChvnPNRFJT7LU0 bzkkllt3AvFxY1/kqdYu9aCRMVOdLAs4Xp+a3ycTNbyhNh65UCq9aIP74Tu9Mc49G27T jK2202y0GvWorelZQ1tZAthRv0+4bslEt7mz0JFclKc34LDSNdDH+I7+owso/3RJ5qgs QbsBLgLgAw7OHBV/dUarWtZ9qoRCA3joFVMhYiIL0JASfI0ntqXxQjXU4EUK/P/lyuBl IDug== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u12si20451329iot.101.2021.08.10.09.23.32; Tue, 10 Aug 2021 09:23:44 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239890AbhHJKrZ (ORCPT + 99 others); Tue, 10 Aug 2021 06:47:25 -0400 Received: from mail-wr1-f41.google.com ([209.85.221.41]:39644 "EHLO mail-wr1-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236505AbhHJKrX (ORCPT ); Tue, 10 Aug 2021 06:47:23 -0400 Received: by mail-wr1-f41.google.com with SMTP id b11so9482805wrx.6; Tue, 10 Aug 2021 03:47:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=P7tG0VICffIvt3SyEoitjgLNgYWI+9vAdgdbLXyUgnA=; b=TGpXId4+nZHv0HTZLL5FmGqAJylZLE4+yaJfuotmpEuNdDkEdfXU9FsuhCrQirL5Bu Uio3j4zXQc5uLutGMI77ZsAgjeaw5ancfJ3zYvC4up9y2a0OUwWlJ926tWuAwWXNIqf+ ww+ot+Ex1aAzne+sj99V870bBPK2way756WqDJxudkhDOOG/Wgoj7fe9oMPy0h36rJZX b1LD9zeC4KAgxrUV1trG9o0NP8HlOvzJQQeGCz7K+zlArRLXtm73Fw/De0lmEvsGWiHJ O9kCgAsxqxMZctsePHjGq25KRawjr1/WyiingPXgvK7QYQN0h6YPLwCKho6foh+0WQua eEaw== X-Gm-Message-State: AOAM531Kq7KmLY+ZNkSQ0PoLCx9aiP2DtUIHF5BBWfg6kvjDL/1SR2Bb IYO2U1l++U9k6Uvg9R0sFzo= X-Received: by 2002:a5d:4852:: with SMTP id n18mr6810873wrs.10.1628592420511; Tue, 10 Aug 2021 03:47:00 -0700 (PDT) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id r8sm899528wmn.0.2021.08.10.03.46.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Aug 2021 03:47:00 -0700 (PDT) Date: Tue, 10 Aug 2021 10:46:58 +0000 From: Wei Liu To: Praveen Kumar Cc: Wei Liu , 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" Subject: Re: [RFC v1 5/8] mshv: add paravirtualized IOMMU support Message-ID: <20210810104658.5ir7cibalhy3roun@liuwe-devbox-debian-v2> 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> <562f4c31-1ea5-ea56-ac0a-6bd80b61c3df@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <562f4c31-1ea5-ea56-ac0a-6bd80b61c3df@linux.microsoft.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 04, 2021 at 12:13:42PM +0530, Praveen Kumar wrote: > 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 Those pages are not really unmapped. The hypercall is skipped. > ... > 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.