Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp748810pxb; Tue, 8 Feb 2022 01:20:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJwysbIKcNGufOJ6G6EIvLYdNk6eSQcnCiDHAm8doZhYiQNvzzCer5FXbZKNLswJezvb2feA X-Received: by 2002:a50:fb04:: with SMTP id d4mr3342015edq.303.1644312041821; Tue, 08 Feb 2022 01:20:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644312041; cv=none; d=google.com; s=arc-20160816; b=rfZ+fqylguY3qoIlFO0EsZHZgiySgU0I6KjWr4dXJJl0S/zty5hlOjFsMMzEZ+qJ53 YRiZ+wpFq6HZL0E2J0Syn5+oeEdvCCFYQHmlZWzvBUt1RoDaZQaRPy6bmaNA4TORJZU/ Nyo5j0iMh7ORHjGga4fKwpCtspU9hburWj9DJ4KS2673vVeUlJluJbnvA77RAaASDT2B JfQPMeKEpD4dbVzmaKwpX9bhxNaqIePUW8D8hJ7sHG/+PpV/7gqwEXn6fSYz8yj02JC3 fhLF/y2/7bxNpUcFa8Hk3rl7Al8FgkbRkbQGwFQRyMU1MFk/XtegKKpu5NqjKKyV+gDq 0oQA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jaT/ksneNKvudiSv5TXaKjVvwKTQT67TlZveRLEmBU0=; b=VGsE3Ed5vidAp183pi/Fwh7caZcXoO3kviqdy6zpnHmP0kAUD3g7ffQzM9JyZlOaB9 PyBVAz/p+UthTjb9qqRH/d3j5BJIORlqCjDRo0eF62+P/bfv+nkDzq8zbb0A5Ov8UVlb 6MlorxbJySFav2w8/ADS4anaQLXT7mhD/5xMW5vzjxFppxWhXFet0k0VnN74UglJNWoL 4tTbNz3Omy6GO+UG+lDc/5hb/zeRb35UZQiLRwudroYN6YVaBR4CYu8nBtwuTK9Q8m+h V/Mi/9Lr/69e48T16ssUm7JvrPMRnDVeTO6xf8raKpBLr5zuy2lI1ZeXANMOTwPpF8yy SP7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="k5/Xj5dc"; 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 11si3401254eje.845.2022.02.08.01.20.16; Tue, 08 Feb 2022 01:20:41 -0800 (PST) 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="k5/Xj5dc"; 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 S1344714AbiBHBDw (ORCPT + 99 others); Mon, 7 Feb 2022 20:03:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245472AbiBGXDb (ORCPT ); Mon, 7 Feb 2022 18:03:31 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0254C06109E for ; Mon, 7 Feb 2022 15:03:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644275010; x=1675811010; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ncFZ3GgiFenQLT9iFwTMGx9ZJmzYJBlebX18EhhOoaA=; b=k5/Xj5dckNbdlxHhvR554H8HV0oJMNJo4BCJSVyWKuKyv6v7uZQr21vw QIiNtk9O+gkSj59NS/guahtkY6U2FNaKWmsezBQxw93scfV9G1/dsK9Wh AJXnMp6arGuMy4K4B/C/wTTwv3QSseaTb9h7BvtdYxiw9JMYEKg0/fTQO cx4ZxI0yyXN00PYZv1xoSubrRlB/CcabQ81zQfLLeAnFHvhIx5Xh1BdSc SEPKHaHHGp75v/KPl1VPkAq4OlnfCIHYKYLXZ5dqof952DF5dd2QELr/E fKFs9oxj5GSjYbNlcMB3upR8Tj17j16PnsxaIjrfkoUj9P4gyHbyZ+K3p A==; X-IronPort-AV: E=McAfee;i="6200,9189,10251"; a="229475024" X-IronPort-AV: E=Sophos;i="5.88,351,1635231600"; d="scan'208";a="229475024" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2022 15:03:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,351,1635231600"; d="scan'208";a="540324104" Received: from otcwcpicx3.sc.intel.com ([172.25.55.73]) by orsmga008.jf.intel.com with ESMTP; 07 Feb 2022 15:03:07 -0800 From: Fenghua Yu To: "Thomas Gleixner" , "Dave Hansen" , "Ingo Molnar" , "Borislav Petkov" , "Peter Zijlstra" , "Andy Lutomirski" , "Tony Luck" , "Lu Baolu" , "Joerg Roedel" , Josh Poimboeuf , "Jacob Pan" , "Ashok Raj" , "Ravi V Shankar" Cc: iommu@lists.linux-foundation.org, "x86" , "linux-kernel" , Fenghua Yu Subject: [PATCH v4 11/11] docs: x86: Change documentation for SVA (Shared Virtual Addressing) Date: Mon, 7 Feb 2022 15:02:54 -0800 Message-Id: <20220207230254.3342514-12-fenghua.yu@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207230254.3342514-1-fenghua.yu@intel.com> References: <20220207230254.3342514-1-fenghua.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 Since allocating, freeing and fixing up PASID are changed, the documentation is updated to reflect the changes. Originally-by: Ashok Raj Signed-off-by: Fenghua Yu Reviewed-by: Tony Luck --- v3: - Remove PASID refcount description (Thomas). v2: - Update life cycle info (Tony and Thomas). - Update initial PASID value to INVALID_IOASID on fork(). Documentation/x86/sva.rst | 53 ++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/Documentation/x86/sva.rst b/Documentation/x86/sva.rst index 076efd51ef1f..1a22020735a3 100644 --- a/Documentation/x86/sva.rst +++ b/Documentation/x86/sva.rst @@ -104,18 +104,47 @@ The MSR must be configured on each logical CPU before any application thread can interact with a device. Threads that belong to the same process share the same page tables, thus the same MSR value. -PASID is cleared when a process is created. The PASID allocation and MSR -programming may occur long after a process and its threads have been created. -One thread must call iommu_sva_bind_device() to allocate the PASID for the -process. If a thread uses ENQCMD without the MSR first being populated, a #GP -will be raised. The kernel will update the PASID MSR with the PASID for all -threads in the process. A single process PASID can be used simultaneously -with multiple devices since they all share the same address space. - -One thread can call iommu_sva_unbind_device() to free the allocated PASID. -The kernel will clear the PASID MSR for all threads belonging to the process. - -New threads inherit the MSR value from the parent. +PASID Life Cycle Management +========================== + +PASID is initialized as INVALID_IOASID (-1) when a process is created. + +Only processes that access SVA-capable devices need to have a PASID +allocated. This allocation happens when a process opens/binds an SVA-capable +device but finds no PASID for this process. Subsequent binds of the same, or +other devices will share the same PASID. + +Although the PASID is allocated to the process by opening a device, +it is not active in any of the threads of that process. It's loaded to the +IA32_PASID MSR lazily when a thread tries to submit a work descriptor +to a device using the ENQCMD. + +That first access will trigger a #GP fault because the IA32_PASID MSR +has not been initialized with the PASID value assigned to the process +when the device was opened. The Linux #GP handler notes that a PASID has +been allocated for the process, and so initializes the IA32_PASID MSR +and returns so that the ENQCMD instruction is re-executed. + +On fork(2) or exec(2) the PASID is removed from the process as it no +longer has the same address space that it had when the device was opened. + +On clone(2) the new task shares the same address space, so will be +able to use the PASID allocated to the process. The IA32_PASID is not +preemptively initialized as the PASID value might not be allocated yet or +the kernel does not know whether this thread is going to access the device +and the cleared IA32_PASID MSR reduces context switch overhead by xstate +init optimization. Since #GP faults have to be handled on any threads that +were created before the PASID was assigned to the mm of the process, newly +created threads might as well be treated in a consistent way. + +Due to complexity of freeing the PASID and clearing all IA32_PASID MSRs in +all threads in unbind, free the PASID lazily only on mm exit. + +If a process does a close(2) of the device file descriptor and munmap(2) +of the device MMIO portal, then the driver will unbind the device. The +PASID is still marked VALID in the PASID_MSR for any threads in the +process that accessed the device. But this is harmless as without the +MMIO portal they cannot submit new work to the device. Relationships ============= -- 2.35.1