Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp270635pxb; Wed, 20 Apr 2022 22:20:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyZ8XAZBbHjzjGp3MhiD7QC3hU1dyW35rqlVQMtDEKBrJWXUcTww7ebIgZj3s/XB8Wj/l7 X-Received: by 2002:a17:906:948:b0:6d6:e479:1fe4 with SMTP id j8-20020a170906094800b006d6e4791fe4mr21141299ejd.240.1650518427862; Wed, 20 Apr 2022 22:20:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650518427; cv=none; d=google.com; s=arc-20160816; b=wT6uEmhO7h6bLj4shULzMyhr2sW2oThlNc7FcoPRnbrjG5AgTUxhRjgQ57BLSUFqjy iIppyFi7U7wfzQWsj9JH9ZfNRsfgssZ0CzyulUvZVi91vSPZykHFh77ut51SDVVBCF94 bDNOg+xBlWA41Hqii40a3TLPMO/wHLwnmINb59gb7tbBqlzcAmTY/FL+CaGO6UsAhgJX zRYAetW4kHSUHegrvNejd2LynpVAADL0cgrbQJlZ8nZE46q16cbJgV+OwwzuJnxLUKcJ svjTwi3nhT7HJt2i9afoDb/NBHWnTmt3ZLX0MXO5LfDWwXXwqqXbSVSRyNvHx7i/U9H4 /jvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=VY6B6xh9asi189ubuNvV3zphfTIxaobPGI6vZIrW9yk=; b=xAIJ9N//DNDa/YtSGdK2zVadaKxFooUdVfNa6+NdJkNIKjgKtfIwGWamZg96PFAqU9 LmzjtNqvddqKjYj2Zk2t3iajZathgxLO09UU6Qncerh0TZURhvetfElOg9XaGZdvW3kv 3IH4kss1Uz/r9S/a7fCrt5EWRoXLTkpR053+Z13lR1jh/kgutTABeQHYEiuBYcj3ezek T8SledPvkNat/OkPQJ508D4bm59RlsmtX5BcQDWjAEKC8tkSrTKCHoveao+0qt7GfnDQ x/2Yx1L54TnoK3ijAQpv5zRioKXAjVBhLJmL+S8fsn3DJNxsD1q8nQddtIKE9Z89rc8+ PfRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YQj2Wk+w; 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 h17-20020aa7cdd1000000b00423b9fe8567si2682327edw.351.2022.04.20.22.20.03; Wed, 20 Apr 2022 22:20:27 -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=YQj2Wk+w; 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 S1347295AbiDRSKn (ORCPT + 99 others); Mon, 18 Apr 2022 14:10:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229651AbiDRSKm (ORCPT ); Mon, 18 Apr 2022 14:10:42 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E426369E5 for ; Mon, 18 Apr 2022 11:08:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650305282; x=1681841282; h=date:from:to:cc:subject:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dyyMH0xpZtsmvKPKBHxyzRSqFnhpIBPEXWOqpua1DEE=; b=YQj2Wk+wvtCBxdy+uZDZsMmnM0HC+CaZ4JM8XrwDBqAtWtSEEEgzaY9o VtBn5qPE5K0tuAPDvRvBO0JF7BkCeZy2MgeN94ENWwM9ywGbNRdVGvOwv oNZv8rTk8dSt8Y2rFmcWN4sDiBsttCkZGS5IP5UUm/m85RfATpJJhNqb1 kY4Uf/Y6EzY4BOwgdIZpmIIS9AcoCSuMfJoYxQNiuBvi7rfDCNOlSja5s zwjYDHwTBg8b/2XCNwzGGrPG+8s/x/fJfw8/GtU61vztofUqVpnD2wWXQ FvORxNpSxfox6zdCiwpNJMST+dFO0PetUx2wdyxdHVHLcJ/+06m1SOV/c A==; X-IronPort-AV: E=McAfee;i="6400,9594,10321"; a="262440361" X-IronPort-AV: E=Sophos;i="5.90,270,1643702400"; d="scan'208";a="262440361" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2022 11:08:01 -0700 X-IronPort-AV: E=Sophos;i="5.90,270,1643702400"; d="scan'208";a="529659339" Received: from jacob-builder.jf.intel.com (HELO jacob-builder) ([10.7.198.157]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2022 11:08:01 -0700 Date: Mon, 18 Apr 2022 11:11:35 -0700 From: Jacob Pan To: "Tian, Kevin" Cc: "zhangfei.gao@foxmail.com" , "Yu, Fenghua" , "Shankar, Ravi V" , "Luck, Tony" , "Raj, Ashok" , jean-philippe , "Peter Zijlstra" , Dave Hansen , x86 , linux-kernel , "Hansen, Dave" , iommu , Ingo Molnar , Borislav Petkov , "Lutomirski, Andy" , "Poimboe, Josh" , Thomas Gleixner , jacob.jun.pan@linux.intel.com Subject: Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit Message-ID: <20220418111135.6260d450@jacob-builder> In-Reply-To: References: <99bcb9f5-4776-9c40-a776-cdecfa9e1010@foxmail.com> <20220415140002.7c12b0d2@jacob-builder> Organization: OTC X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 Hi Kevin, On Mon, 18 Apr 2022 06:34:19 +0000, "Tian, Kevin" wrote: > > From: Jacob Pan > > Sent: Saturday, April 16, 2022 5:00 AM > > > > Hi zhangfei.gao@foxmail.com, > > > > On Fri, 15 Apr 2022 19:52:03 +0800, "zhangfei.gao@foxmail.com" > > wrote: > > > > > >>> A PASID might be still used even though it is freed on mm exit. > > > >>> > > > >>> process A: > > > >>> sva_bind(); > > > >>> ioasid_alloc() = N; // Get PASID N for the mm > > > >>> fork(): // spawn process B > > > >>> exit(); > > > >>> ioasid_free(N); > > > >>> > > > >>> process B: > > > >>> device uses PASID N -> failure > > > >>> sva_unbind(); > > > >>> > > > >>> Dave Hansen suggests to take a refcount on the mm whenever > > > >>> binding > > the > > > >>> PASID to a device and drop the refcount on unbinding. The mm > > > >>> won't > > be > > > >>> dropped if the PASID is still bound to it. > > > >>> > > > >>> Fixes: 701fac40384f ("iommu/sva: Assign a PASID to mm on PASID > > > >>> allocation and free it on mm exit") > > > >>> > > Is process A's mm intended to be used by process B? Or you really should > > use PASID N on process B's mm? If the latter, it may work for a while > > until B changes mapping. > > > > It seems you are just extending the life of a defunct mm? > > > > IMHO the intention is not to allow B to access A's mm. > > The problem is that PASID N is released on exit() of A and then > reallocated to B before iommu driver gets the chance to quiesce > the device and clear the PASID entry. According to the discussion > the quiesce operation must be done when driver calls unbind() > instead of in mm exit. In this case a failure is reported when > B tries to call bind() on PASID N due to an already-present entry. > > Dave's patch extending the life of A's mm until unbind() is called. > With it B either gets a different PASID before A's unbind() is > completed or same PASID N pointing to B's mm after A's unbind(). > As long as B gets a different PASID, that is fine. It seems PASID N has no use then. > Thanks > Kevin Thanks, Jacob