Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1782165rwo; Wed, 2 Aug 2023 22:27:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlGkYE9u0B/Aled6HMIQAe6e+N2HINVWJeHUPg072g8cuNn5L4p25DyWxRqzAWPua72CAVX1 X-Received: by 2002:a05:6402:2812:b0:522:28b9:e84c with SMTP id h18-20020a056402281200b0052228b9e84cmr9726790ede.21.1691040434959; Wed, 02 Aug 2023 22:27:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691040434; cv=none; d=google.com; s=arc-20160816; b=r2mpBjF9AYiRo/mFVlJBApXMoZilfg9gULwQngnpPhW9xLO8K5hbKGXPOU5xKI2lxC 2zcE4KKFSoS2zcSall/D3R2OOgGXX4gbLdcqbtjY/btTvf+YQcOqArN+0qsE7Fb8gRBz tT1wXFjSR0BcNhtp0JIAMFi9l/9YbA5y94KXgu5NB+uEwt8yCLxn86EwDfRGqR8HScfn zQaSmWcGqXMlJ0BCmZm7mbh+1IYDIruWnRzxeXXqC7fzIJIOuiPqTdf7RT3xyfpTB9uH 0wQjmgX5MxobnvWhHh7T0MWz6tL9OT22J8W/R4jh/i/dLtjIWB1xfJE3n6zoi8Cejodp OiVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=3tBg+u9cmOHBpm6ka+7rL6zVtxQ4bOCBAZKTf7hi3j4=; fh=hdYmtqyQCNDe3R1Iumq8dz39VpjWGW1O+FEAZ6WRddI=; b=qtmwDrkouHo9/wiuh1KnaLHcHMxeZBQQavKx+AySoGaQhiPaqErxdEp/Vkqmc3nIeI StlPjY+9JX8EcloEJjPpyMAka1SoyxMvsF8w7zbpi+MZAVWdaZoxIQOxinJvSGAWbutn VngGea+pi6/iXEzgvPDzDL1HofZNsnO4WoX0m4poGndyXor7i2DhHUfhqE9pg5pMfKG2 siOYXiI8+pPj0vL9XN8GpkAYbbl4oeXqKMx0Flu4HDQ/MRkSI/vD5CV+zHRlC7H64bNo XbGa9FrNTjJMUMk/kUuZJRe8HqM0Z5TT0ZUK+3vNCYKi9BJ623VzdCfQi1IJEQtFvcsc /BWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="H/mgz5ld"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w15-20020aa7dccf000000b0052237dfa831si11048175edu.541.2023.08.02.22.26.51; Wed, 02 Aug 2023 22:27:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="H/mgz5ld"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233159AbjHCDZz (ORCPT + 99 others); Wed, 2 Aug 2023 23:25:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232362AbjHCDZN (ORCPT ); Wed, 2 Aug 2023 23:25:13 -0400 Received: from mgamail.intel.com (unknown [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 342D230D3; Wed, 2 Aug 2023 20:24:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1691033088; x=1722569088; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=ICQshYmMfbXZrwMngTGz4HUFiYda9PJa/FB3HICeWPs=; b=H/mgz5ldWeM56GcB0a7HhGSHj1imk/vE2u/FSdULKhWYhGX7k+nYxc6x caA761u0lw9iOO5fVotwNNVIlKQ93D1HSwt8ihwJaeagGjJhikWLk6IiF 8y6afutuKsOiMhTv5swBNQdC5FY0zDdH9KDtD7vSFys+Isz5Ip1iGvK86 Trr9sqwTBRU7iieuHZFtapx+a/gq8CjehmLBfu4yPw7M3iOEryvZoIrYF 5ztAa5w8dU+/YiqV+lcT/GCXzkOgMON/7txzh1bjN9CLGFEVCNq6yCWDX J4WzAE4jHeFeYbJ+C0h1LIla/v4Z2YPuKATDtQQ6XzNnYE3I4/1yDAQh8 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10790"; a="350050674" X-IronPort-AV: E=Sophos;i="6.01,251,1684825200"; d="scan'208";a="350050674" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2023 20:24:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10790"; a="1060074437" X-IronPort-AV: E=Sophos;i="6.01,251,1684825200"; d="scan'208";a="1060074437" Received: from blu2-mobl.ccr.corp.intel.com (HELO [10.255.31.34]) ([10.255.31.34]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2023 20:24:42 -0700 Message-ID: <58ae9095-28f2-a44a-b0e5-be82e1eae9d9@linux.intel.com> Date: Thu, 3 Aug 2023 11:24:40 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Cc: baolu.lu@linux.intel.com, "cohuck@redhat.com" , "eric.auger@redhat.com" , "nicolinc@nvidia.com" , "kvm@vger.kernel.org" , "mjrosato@linux.ibm.com" , "chao.p.peng@linux.intel.com" , "yi.y.sun@linux.intel.com" , "peterx@redhat.com" , "jasowang@redhat.com" , "shameerali.kolothum.thodi@huawei.com" , "lulu@redhat.com" , "suravee.suthikulpanit@amd.com" , "iommu@lists.linux.dev" , "linux-kernel@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , "Duan, Zhenzhong" Subject: Re: [PATCH v4 09/12] iommu/vt-d: Add iotlb flush for nested domain Content-Language: en-US To: "Tian, Kevin" , "Liu, Yi L" , "joro@8bytes.org" , "alex.williamson@redhat.com" , "jgg@nvidia.com" , "robin.murphy@arm.com" References: <20230724111335.107427-1-yi.l.liu@intel.com> <20230724111335.107427-10-yi.l.liu@intel.com> From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/8/2 15:46, Tian, Kevin wrote: >> From: Liu, Yi L >> Sent: Monday, July 24, 2023 7:14 PM >> >> +static int intel_nested_cache_invalidate_user(struct iommu_domain >> *domain, >> + void *user_data) >> +{ >> + struct iommu_hwpt_vtd_s1_invalidate_desc *req = user_data; >> + struct iommu_hwpt_vtd_s1_invalidate *inv_info = user_data; >> + struct dmar_domain *dmar_domain = to_dmar_domain(domain); >> + unsigned int entry_size = inv_info->entry_size; >> + u64 uptr = inv_info->inv_data_uptr; >> + u64 nr_uptr = inv_info->entry_nr_uptr; >> + struct device_domain_info *info; >> + u32 entry_nr, index; >> + unsigned long flags; >> + int ret = 0; >> + >> + if (get_user(entry_nr, (uint32_t __user *)u64_to_user_ptr(nr_uptr))) >> + return -EFAULT; >> + >> + for (index = 0; index < entry_nr; index++) { >> + ret = copy_struct_from_user(req, sizeof(*req), >> + u64_to_user_ptr(uptr + index * >> entry_size), >> + entry_size); > > If continuing this direction then the driver should also check minsz etc. > for struct iommu_hwpt_vtd_s1_invalidate and iommu_hwpt_vtd_s1_invalidate_desc > since they are uAPI and subject to change. Agreed. > >> + if (ret) { >> + pr_err_ratelimited("Failed to fetch invalidation >> request\n"); >> + break; >> + } >> + >> + if (req->__reserved || (req->flags & >> ~IOMMU_VTD_QI_FLAGS_LEAF) || >> + !IS_ALIGNED(req->addr, VTD_PAGE_SIZE)) { >> + ret = -EINVAL; >> + break; >> + } >> + >> + spin_lock_irqsave(&dmar_domain->lock, flags); >> + list_for_each_entry(info, &dmar_domain->devices, link) >> + intel_nested_invalidate(info->dev, dmar_domain, >> + req->addr, req->npages); >> + spin_unlock_irqrestore(&dmar_domain->lock, flags); > > Disabling interrupt while invalidating iotlb is certainly unacceptable. > > Actually there is no need to walk devices. Under dmar_domain there > is already a list of attached iommu's. Walking device is only necessary when invalidating device TLB. For iotlb invalidation, it only needs to know the iommu's. Best regards, baolu