Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp364856rwd; Tue, 30 May 2023 22:26:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7G6RtvsKb4fzXmPuhiXQeFXT2InZBlZOOP44zJDEz+Jz7X2rU73vc59TOBkxE5KZmT8x7h X-Received: by 2002:ac8:7d95:0:b0:3f4:8612:6d84 with SMTP id c21-20020ac87d95000000b003f486126d84mr5253920qtd.60.1685510808754; Tue, 30 May 2023 22:26:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685510808; cv=none; d=google.com; s=arc-20160816; b=Xx4UBopiLxKhkiDLkhXNpVPjDtbLgqZDsLbk7dUYeK7NRF4YOF5S4ECrl7LE6pUF/Z HXn51tEAaNEzSXaHZPjnGwNVPu+jr9S2vgSWTkuy2ARYWMV4VMrM1pkF3E+dlfNBF2sx 5jtU/EQEZKx3qxqHIEd/kR9uPTpUgsaHxRI5pwotm+TYrnoRp5616rH21i8ChbmLzMGA 7E5bf09X23yJqRcv2wTON/sTYf9jalOQeCnxNtG7HsrgtSktO1r59PPCVf8aDVsgI3Qs ciwaVqyP0WUvLEkkP323CaI5SvDZNIzrJNeFmc5Fw3y3d+mZgoIztozkjaNGKBBOMZ0C wTgg== 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=vI1O2LVIorQ2ZSSKWxMupKxkQl34myOH473lFqFGt5g=; b=WudNb7KUJN01pFstOgwFonNL0uVmp0YgKrcs9GC/REX3H1MKP0Oi+58VlpC+qjJgpt mhzq49K7Wkfk0uJNh9aiXVG/zZJoa8jZqMrS7N/qxsQOeUISO6N0PKddFKre2w3H2EDK CbCMg540NXF3GVT4+wv9hQTYh4eh/QmIkg03d7dsTvnomjKbwvwq7XR7+72/pZPVR+My ljKG7VPMcv78GFG+IeZi62gbDGwBizgZgsuslI2KSKkj6ybEamT3EZUlP7+IDp1qVpCC vKnHghWV+uObW+encmc0FY+lpwZ7d556VYJkmJgdyLQN61PkS+U95m0DNDT6gh+UlMnv SRmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hLBwIp6F; 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 u198-20020a6379cf000000b00528d90d40e2si323008pgc.891.2023.05.30.22.26.34; Tue, 30 May 2023 22:26:48 -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=hLBwIp6F; 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 S232822AbjEaFAt (ORCPT + 99 others); Wed, 31 May 2023 01:00:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231150AbjEaFAq (ORCPT ); Wed, 31 May 2023 01:00:46 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01BE4E5; Tue, 30 May 2023 22:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685509245; x=1717045245; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=Mxzw9zYTykOHn7N954LEKaf1cblcwqFC37xLIQx1JMw=; b=hLBwIp6FaGA1OhR5JH78nCJ1c62INONwn5p2iz/NC/ZmbFW4cyVnMoIU 5vqkv7KWZx7U4hL26t1yEaWfi7dkxZHtv9JstOFOv9ZwEhPoqAPgXKdRN xSV3pI1KcatakoOU/CdZD71v0iJfIjC/2PWfVAFfw2u+ViOElyoc360WD VZyERDvgX/dEW7wyUuYCU0fuQZm5Qsc8P75LXKzUpUX1izXhmPQrC8bQW WtFmCIuwxOzOYZYJbF9ChtmnrkINouWvYXlfmSwEAqCVRywRCkzbEO+RB CMhpt917Xt3vebSyeBQEH9ljzo/ED2Qmo2U/BgprW+kUYhzjV+8+Tz5xh A==; X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="357525020" X-IronPort-AV: E=Sophos;i="6.00,205,1681196400"; d="scan'208";a="357525020" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 May 2023 22:00:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10726"; a="684263058" X-IronPort-AV: E=Sophos;i="6.00,205,1681196400"; d="scan'208";a="684263058" Received: from allen-box.sh.intel.com (HELO [10.239.159.127]) ([10.239.159.127]) by orsmga006.jf.intel.com with ESMTP; 30 May 2023 22:00:39 -0700 Message-ID: Date: Wed, 31 May 2023 12:59:44 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Cc: baolu.lu@linux.intel.com, Jacob Pan , LKML , "iommu@lists.linux.dev" , Joerg Roedel , Robin Murphy , Jean-Philippe Brucker , "dmaengine@vger.kernel.org" , "vkoul@kernel.org" , Will Deacon , David Woodhouse , "Raj, Ashok" , "Liu, Yi L" , "Yu, Fenghua" , "Jiang, Dave" , "Luck, Tony" , "Zanussi, Tom" , "Ranganathan, Narayan" Subject: Re: [PATCH v7 3/4] iommu/vt-d: Add set_dev_pasid callback for dma domain Content-Language: en-US To: Jason Gunthorpe , "Tian, Kevin" References: <20230523173451.2932113-1-jacob.jun.pan@linux.intel.com> <20230523173451.2932113-4-jacob.jun.pan@linux.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=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 5/31/23 1:08 AM, Jason Gunthorpe wrote: >>> + /* >>> + * The SVA implementation needs to stop mm notification, drain the >>> + * pending page fault requests before tearing down the pasid entry. >>> + * The VT-d spec (section 6.2.3.1) also recommends that software >>> + * could use a reserved domain id for all first-only and pass-through >>> + * translations. Hence there's no need to call >>> domain_detach_iommu() >>> + * in the sva domain case. >>> + */ >> >> It's probably clearer to say: > > Is this what is going on ?? > >> /* >> * SVA domain requires special treatment before tearing down the pasid >> * entry: >> * 1) pasid is stored in mm instead of in dev_pasid; > > Why? The mm pasid should not be used by any driver code, the PASID the > SVA is hooked to does NOT have to be the mm PASID. Yes. The individual driver should not be aware of mm->pasid. The set/remove_dev_pasid callbacks have already take pasid as the inputs. > >> * 2) all SVA domains share a reserved domain id per recommendation >> * from VT-d spec (section 6.2.3.1) so domain_detach_iommu() is >> * not required; > > The DID should be managed and allocated for the S2 pointer and the > flushing logic should work genericly by tracking the S2's being used > and flushing their DIDs when all the S2s fall out of use. The special > identity S2 just gets a static DID that never falls out of use. The DID logic in this case is not about invalidating the DID. Instead, it is about managing the DID's reference count to track its allocation and release. The reference count is increased every time the DID is assigned to hardware, and it is decreased when the DID is removed from hardware. The DID is released when the count hits 0. Some DIDs are reserved for special domains, like identity domain, SVA domain, etc. For those DIDs, there's no need for reference count, hence no need to call the helper. For code simplify, perhaps we can enhance the helpers to take no action for those special DIDs. Best regards, baolu