Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp67034lfe; Fri, 15 Apr 2022 19:50:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHHhsyXGW4N5HAxE+9HoQsFe/X3IWvBDM3d/RHYMg/ho8gWLgxhaHSExgu4hWQWhH2pTNo X-Received: by 2002:a17:902:d488:b0:158:e7d1:fc16 with SMTP id c8-20020a170902d48800b00158e7d1fc16mr1593706plg.171.1650077449507; Fri, 15 Apr 2022 19:50:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650077449; cv=none; d=google.com; s=arc-20160816; b=oyXuMQD9IROROWkMYv+KE700D2eE3p5v1P+5q9v302n6aPwzIgSO/0ku45vNmJDTZR lJG502J0iNtc7PjXujw6MI5XqVXkGvFP5JvtA+MbBSeMZjjAPCWBa8nOZsGFJNHIuA1o FcSAYfunJ1GEIeOrK2pxO9fqJXlNyujO04J81rsn7s5hxP+UIrk+fmm9UhLfZsYm3Vkb pKHKpr6KZjSAvbN/eLgVsjMc6pTo2zPL4L3FvIdWgS86Dsv5Vte73fEafiyniDOpsu7H F0GodAx55/YFOoLVUgM2+atqc70FgR68pPRZqYJegToykTWI/KYYert57I4xctzoc6Ii fZEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:from:references:cc:to :subject:message-id:dkim-signature; bh=CriwDWtOWAQX5VANr5fAIAkGQbBAnagbCEroVjZL5xE=; b=BVk4vf1nN+iZ2JmGdBd1D/NZxGd3EvgXAVvocrCri2+Ai/wWMjdJRled5JCQHVMb1t riV4j8pdl0dOX4q8h4f7Zp2hQMcLwSDU9ZUpZCvR59UsoRnomVxPkEkZpysT79nzGn4o eWY0kQ/vLptaLXTyuwyLz7Y0PGczFB0xx4m4VE89boEZmIqq8uJJ/s1wN8dVKxVL86T8 vMqU2eYGtmzktnFWpCZawUKmEYQpFuMbwUrYfD+2sBMx2OlS3qZvYRa7ZU7DSOEi6560 bgh3bSOTM8PqaXWZczaDWw1U3OninId8jk8bqELqIz9Nza22UGX2W9kvG889ROFLXA1J Hpug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=NTRnOIaH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id a71-20020a63904a000000b0038251571eacsi2873673pge.180.2022.04.15.19.50.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:50:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@foxmail.com header.s=s201512 header.b=NTRnOIaH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 47C5F75C02; Fri, 15 Apr 2022 19:08:15 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229745AbiDPCG6 (ORCPT + 99 others); Fri, 15 Apr 2022 22:06:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229620AbiDPCGD (ORCPT ); Fri, 15 Apr 2022 22:06:03 -0400 Received: from out203-205-251-60.mail.qq.com (out203-205-251-60.mail.qq.com [203.205.251.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63D8F6D4E5 for ; Fri, 15 Apr 2022 18:58:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1650074332; bh=CriwDWtOWAQX5VANr5fAIAkGQbBAnagbCEroVjZL5xE=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=NTRnOIaHyemr/JoHOXrNcIwV+urI6oIdsGlqBmMV7bxymwyVaIdf0dcpXbodWKjI1 6bmhN6NuqwVtHhxsdJoJjJUncKPGcBWgbbxn+XfgWDl3v99oZsz47JRo3i3VdMAkkb BnFNbS5f/wrLjxHneUqI730/6Vm3QDb4qQY0HjzI= Received: from [IPv6:240e:362:47d:9500:6527:51dc:8ce2:179e] ([240e:362:47d:9500:6527:51dc:8ce2:179e]) by newxmesmtplogicsvrszc7.qq.com (NewEsmtp) with SMTP id AD38087B; Sat, 16 Apr 2022 09:43:19 +0800 X-QQ-mid: xmsmtpt1650073399tvl7nvia6 Message-ID: X-QQ-XMAILINFO: NY3HYYTs4gYSrO+zHxGJ/iwzNSjLXu9vUBN6PnZHIBGTm9jqMKPbKBgmf1wIfN fUnS32uHdLgy3E17MQn5nFZSjeuCUdYakAG0ji4xpE2GYKNVYpdnhhiMAyVYLaYzjVramRVd2o6T PBKHwjgnLhPCmooQY8Laqj4OEKZkrHDUYaNs6LU0sl3pPhLu9tkGtd7ookVkvph0+UidYKAunvTl z64mBPOAzGtjKjINLBHRpyPODP9pwo///ZZYbqaX/8sZ9yXWUo65C/WPy8YoOlqhnHs8VqUSMZLP h7/QcFSpSabezlKuABc/Wc/pjNosbHwzpDVAWJ9XolbEH93SZPppBI5AMRueJubQh+/vV6hHOKHR Y+AFXbM4k/ES7/0nxIZfWygx2H4lW7tefGlAaGII6lLDYSSHCqfjVpmrGKkY0Zd2TU6QlpNrSD7O 7QWzcDuxN6wQUBngabozrXDxiyeXEpoclQka7rTkMp3+/5Euph5yL1mqelcqQunVwmuPTv1w+iUz WxAGWWWQkwg/8dzxw/NdUDUzSo5OWhYFlYkxLLzlDLZMUMIehLrrF0+gLFfGbzUkF5RS7a8q3IJb 8lrJzBymc56Fn/tztPziAJBerWZxZ3+c8tF7zcBjUZP9dSZNb2blYQZw+VVvxDTb5igATok3q35O 6PIQGZkUpGXIW5e0/M9ZEfI1eTTEzcQ2lopQigFZnhNAZ3lu/1+4jc8P1v8uJC/hezPlSX1BKFvi y6O5YlLO9pbmg+Zu0uqrecPrFhfwamuTbcuYhgHZyxEY6aPA64xzsL7ESon5Rrz4jL1z08ULC3CU xNAp8smcjAtTgyp37Z+QYLn5SKilhvPcZx5jn3ME9bKAuWX6oh4QE/+ASY50DPki7FRfUaqp60rk 63jl0c74ddlK+VrqzWWIu0WF629TKIDoj/id2Z1rgmyE8kz20Viyu9zOXNU+hmCMecUiG/Xh/ZsB y5FqaZTq2OEsJN4wfz7Q== Subject: Re: [PATCH v4 05/11] iommu/sva: Assign a PASID to mm on PASID allocation and free it on mm exit To: Jacob Pan 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 References: <99bcb9f5-4776-9c40-a776-cdecfa9e1010@foxmail.com> <20220415140002.7c12b0d2@jacob-builder> From: "zhangfei.gao@foxmail.com" X-OQ-MSGID: Date: Sat, 16 Apr 2022 09:43:07 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20220415140002.7c12b0d2@jacob-builder> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FORGED_MUA_MOZILLA,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 2022/4/16 上午5:00, Jacob Pan wrote: > 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? From nginx code, the master process init resources, then fork daemon process to take over, then master process exit by itself. src/core/nginx.c main ngx_ssl_init(log);    -> openssl engine -> bind_fn -> sva_bind() ngx_daemon(cycle->log) src/os/unix/ngx_daemon.c ngx_daemon(ngx_log_t *log) {      int  fd;      switch (fork()) {      case -1:          ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "fork() failed");          return NGX_ERROR;      case 0:         // the fork daemon process          break;      default:        // master process directly exit, and release mm as well as ioasid          exit(0);      }       // only daemon process Thanks > > Thanks, > > Jacob