Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3511452pxb; Tue, 19 Apr 2022 04:22:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwl1PUf5npJAs8eW31Y2XTj6Cw367xXd9pZyiOn2lwxPAWL3NAJ8T35TJr6Nrz9dEl1aWgZ X-Received: by 2002:a17:907:7f0d:b0:6e8:ecfa:996c with SMTP id qf13-20020a1709077f0d00b006e8ecfa996cmr12594506ejc.7.1650367376949; Tue, 19 Apr 2022 04:22:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650367376; cv=none; d=google.com; s=arc-20160816; b=fb7JEm6eqRi/3E7ShWQ7cV8inFoUEJ0OCgNTt+PIznl0vshSD1t7xG6lOb1sgECzrI OXWOtXGFH16Uhzwto8mLvfxZ+dNbk7vRRveuy38K6eBzvXQDie+Hv8CpJcRky/PtxsZl oMAay5wO8lZYsBLqgvYng/v4VposNjvhY3mANdtMFx8GUFtrDVv7pzU9w8kADascGFUa ejkp4CBk0XCfT+cwgt4q9ZISiBEkTZA3RXuTdN9o7bdQUgIzO/PG7pu9z2AEFIhymgDe sSORx4grjwiLmsnzDGs23dsyknIyDxTEk95Ng7/AlmHVKXiqIzQW5e/JQlMEWAHefaor +yhg== 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=RulMH/q6xYc7V+//1txzBy3tb7JpCkusrtkL2F9aMQY=; b=s3K8M5qts2X5uSRgT7pidGw6pqnBbtJkcI2IN2OQpZISkrhxc9xCdqKzsGQvA+OHi6 7flF80crxEwUofr0oTk58yTi4nusff8SI5xY7QNZayP/nOx6ZRiLFxSzLL/IuVpGeQBA ORzE0am1p2WaXVi26qj87CIYGH8ptii6nSgClYYJVImuNTzeLzck6UCL/seYzOt18vVZ I0FDBS2ZI+s1lI4T+fX0iaHS7Jrv7jCA2zK5RHjwyzObUs3Izl915P/d6QHA4nUAcazL LFsH3VLnseFSLqokOqby5C7Jau+AwJfbgQtmJ0xW5bLYvWtpsFxmX71mf4S2bdT9SiV+ wREQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=X1eskVLy; 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 v10-20020a056402348a00b0041d896e9d91si9363401edc.219.2022.04.19.04.22.32; Tue, 19 Apr 2022 04:22:56 -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=X1eskVLy; 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 S1347345AbiDRSOE (ORCPT + 99 others); Mon, 18 Apr 2022 14:14:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbiDRSOD (ORCPT ); Mon, 18 Apr 2022 14:14:03 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A56E25289 for ; Mon, 18 Apr 2022 11:11:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650305484; x=1681841484; h=date:from:to:cc:subject:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4FtieXzTSKHMKDV88WzqEoh+kHjDQfwJ0Yydw1piwHk=; b=X1eskVLyDY6NiXcM38yERkGHT9mxXtBX8sLPWxq4WcePUr+AibLfQCJq jUr8nIYpBkp0FgKDVzIBO4g0IJ1TuRuQ+Xq6UttuiWoh5H1611FixgWuU 0lxLgZIN2Cr5FXBYbVSNAsT5VMkAHPP/smN99K9RbGxH3aZalw/l7sjaf cHRngC86Os4SVahRQEtuZhEvrXJ6P6yZXbgGk4a6O2G7T9uLRtcMzUOAU JZ9BhcbK9Jt4/f0pbT9AQymIKAzNLZrYDYSCnIN+7VazymVmfOdhKwrgV N4903fA6qqeGCIGBGrT0q2WCuaKGCbeiQ17/TlIWo1Wj7h82AQLxpErTf g==; X-IronPort-AV: E=McAfee;i="6400,9594,10321"; a="350030822" X-IronPort-AV: E=Sophos;i="5.90,270,1643702400"; d="scan'208";a="350030822" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2022 11:11:23 -0700 X-IronPort-AV: E=Sophos;i="5.90,270,1643702400"; d="scan'208";a="646948978" Received: from jacob-builder.jf.intel.com (HELO jacob-builder) ([10.7.198.157]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2022 11:11:22 -0700 Date: Mon, 18 Apr 2022 11:14:56 -0700 From: Jacob Pan To: "zhangfei.gao@foxmail.com" Cc: Fenghua Yu , Ravi V Shankar , Tony Luck , Ashok Raj , jean-philippe , Peter Zijlstra , Dave Hansen , x86 , linux-kernel , Dave Hansen , iommu , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Josh Poimboeuf , 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: <20220418111456.2f1a1285@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=UTF-8 Content-Transfer-Encoding: quoted-printable 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 zhangfei.gao@foxmail.com, On Sat, 16 Apr 2022 09:43:07 +0800, "zhangfei.gao@foxmail.com" wrote: > On 2022/4/16 =E4=B8=8A=E5=8D=885:00, Jacob Pan wrote: > > Hi zhangfei.gao@foxmail.com, > > > > On Fri, 15 Apr 2022 19:52:03 +0800, "zhangfei.gao@foxmail.com" > > wrote: > > =20 > >>>>> A PASID might be still used even though it is freed on mm exit. > >>>>> > >>>>> process A: > >>>>> sva_bind(); > >>>>> ioasid_alloc() =3D 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") > >>>>> =20 > > 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? =20 >=20 > From nginx code, the master process init resources, then fork daemon=20 > process to take over, > then master process exit by itself. >=20 > src/core/nginx.c > main > ngx_ssl_init(log);=C2=A0=C2=A0=C2=A0 -> openssl engine -> bind_fn -> sva_= bind() > ngx_daemon(cycle->log) >=20 > src/os/unix/ngx_daemon.c > ngx_daemon(ngx_log_t *log) > { > =C2=A0=C2=A0=C2=A0=C2=A0 int=C2=A0 fd; >=20 > =C2=A0=C2=A0=C2=A0=C2=A0 switch (fork()) { > =C2=A0=C2=A0=C2=A0=C2=A0 case -1: > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ngx_log_error(NGX_LOG_E= MERG, log, ngx_errno, "fork() failed"); > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return NGX_ERROR; >=20 > =C2=A0=C2=A0=C2=A0=C2=A0 case 0: > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // the fork daemon process > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 break; >=20 Does this child process call sva_bind() again to get another PASID? Or it will keep using the parent's PASID for DMA? > =C2=A0=C2=A0=C2=A0=C2=A0 default: > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // master process directly exit, an= d release mm as well as ioasid > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 exit(0); > =C2=A0=C2=A0=C2=A0=C2=A0 } >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // only daemon process >=20 > Thanks >=20 > > > > Thanks, > > > > Jacob =20 >=20 Thanks, Jacob