From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EA11C433F5 for ; Thu, 23 Sep 2021 23:09:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 41A5661250 for ; Thu, 23 Sep 2021 23:09:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243557AbhIWXLR (ORCPT ); Thu, 23 Sep 2021 19:11:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:46156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236363AbhIWXLQ (ORCPT ); Thu, 23 Sep 2021 19:11:16 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 837A861107; Thu, 23 Sep 2021 23:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632438583; bh=N5cuTMmeZEkv0jHourxdJkh/zB3vziTEXWj25gMIcvE=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=VwhSiUXbg4mGx+IRNOlnUS918ijpj2HG2O8Is2jqB4Oz1ZrnuGA+cFWCCZWYlAXHK vcdntZnT5F/brH6v+e9fYJC1EApmRkhmdXyhc1yWG9RpMw31SzH5V58ayjhLM2vcE7 40xVEbjdkJAqxOI1HGqyMJ68f/SAkPHqI9dY0ENHif0CCMnGGhx9BnLWEbM83bpKa5 +vbqWClgc6UzmcQB5urCiaMENKHDEM0kFJFEFh7gGHLLihPkJkFWx8o3jygHSJFfie R0Cv2ryb6FMDHab3/BkbymwIpJTH6LnlS4iNy7OK4yI3L8ZJpcg7We+tZIlkbMF2Hr fn+Uy9mZbZzKg== Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id A49FF27C0054; Thu, 23 Sep 2021 19:09:41 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute6.internal (MEProxy); Thu, 23 Sep 2021 19:09:41 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudejtddgudejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdetnhgu hicunfhuthhomhhirhhskhhifdcuoehluhhtoheskhgvrhhnvghlrdhorhhgqeenucggtf frrghtthgvrhhnpedthfehtedtvdetvdetudfgueeuhfdtudegvdelveelfedvteelfffg fedvkeegfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpegrnhguhidomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqudduiedukeeh ieefvddqvdeifeduieeitdekqdhluhhtoheppehkvghrnhgvlhdrohhrgheslhhinhhugi drlhhuthhordhush X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id AFE5521E0063; Thu, 23 Sep 2021 19:09:40 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-1303-gb2406efd75-fm-20210922.002-gb2406efd Mime-Version: 1.0 Message-Id: In-Reply-To: <20210920192349.2602141-6-fenghua.yu@intel.com> References: <20210920192349.2602141-1-fenghua.yu@intel.com> <20210920192349.2602141-6-fenghua.yu@intel.com> Date: Thu, 23 Sep 2021 16:09:18 -0700 From: "Andy Lutomirski" To: "Fenghua Yu" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Peter Zijlstra (Intel)" , "Dave Hansen" , "Tony Luck" , "Lu Baolu" , "Joerg Roedel" , "Josh Poimboeuf" , "Dave Jiang" , "Jacob Jun Pan" , "Raj Ashok" , "Shankar, Ravi V" Cc: iommu@lists.linux-foundation.org, "the arch/x86 maintainers" , "Linux Kernel Mailing List" Subject: Re: [PATCH 5/8] x86/mmu: Add mm-based PASID refcounting Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 20, 2021, at 12:23 PM, Fenghua Yu wrote: > PASIDs are fundamentally hardware resources in a shared address space. > There is a limited number of them to use ENQCMD on shared workqueue. > They must be shared and managed. They can not, for instance, be > statically allocated to processes. > > Free PASID eagerly by sending IPIs in unbind was disabled due to locking > and other issues in commit 9bfecd058339 ("x86/cpufeatures: Force disable > X86_FEATURE_ENQCMD and remove update_pasid()"). > > Lazy PASID free is implemented in order to re-enable the ENQCMD feature. > PASIDs are currently reference counted and are centered around device > usage. To support lazy PASID free, reference counts are tracked in the > following scenarios: > > 1. The PASID's reference count is initialized as 1 when the PASID is first > allocated in bind. This is already implemented. > 2. A reference is taken when a device is bound to the mm and dropped > when the device is unbound from the mm. This reference tracks device > usage of the PASID. This is already implemented. > 3. A reference is taken when a task's IA32_PASID MSR is initialized in > #GP fix up and dropped when the task exits. This reference tracks > the task usage of the PASID. It is implemented here. I think this is unnecessarily complicated because it's buying in to the existing ISA misconception that PASID has anything to do with a task. A PASID belongs to an mm, full stop. Now the ISA is nasty and we have tasks that have *noticed* that their mm has a PASID and tasks that have not noticed this fact, but that should be irrelevant to essentially everything except the fault handler. So just refcount the thing the obvious way: take a reference when you stick the PASID in the mm_struct and drop the reference in __mmdrop(). Problem solved. You could probably drop it more aggressively in __mmput(), and the comment explaining why is left as an exercise to the reader -- if a kernel thread starts doing ENQCMD, we have worse things to worry about :) --Andy