Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1019964pxb; Thu, 23 Sep 2021 16:11:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZ5IZoJCI3/XYOPW3xKWnIbs1otK1S/N/x3pG0v+3D63T7ojdaeUDiBhyd3SFa/H0hMQhS X-Received: by 2002:a02:6048:: with SMTP id d8mr6313990jaf.61.1632438681195; Thu, 23 Sep 2021 16:11:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632438681; cv=none; d=google.com; s=arc-20160816; b=HvWhIO0c3qaiLFHzzYcxDWHD67kR4i+U4O7ebk5cFZ0OMBcreHgzH6UO94iS+yFzYg CqN6RsTQ2lljXXEJwsgLPTlXAPSxK/GIunpJZt39F1upLRWXZgpImXiIyna/tzAplt+U D8AGdGTJNj3PeqRjEjmlKGxdsA0vIeXnEvQUFQxzFP0rL+Fc5WgarD8lJg5X6uFa5Go2 az/mrCS1HB1F462cbS1zGfai2QQA2tKASkVBd/gYnflxvfahja6mP9mWvHxAHOMZmOQL rCnOdSYBEkBp2v94h7RuAjgho2HoaQ2F/I8ZK8UC9g9P7700KUTfMYhI57107Il0VaBO 3rXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:dkim-signature; bh=bcOYPEGII3wJhGumz7U8AOHXVzsVL2oneMM4JmHdOoo=; b=cUbWUOTmZvsWp8ARJ6VolUiKAys+oCqR4Mr4PHHVbArwcwVmMjGfrBWiCg86ghYYvD 2xGCQ7hghGucHa2aWBOq6rT0AT+PgTv/gxHSd2407+9Mr/7U2GjX8opMvXPs5bK1XMf8 DTW+zSkIF70860SKYmXIB9YDJSzJVNuGqXaMnV/Eqphz5Sy3Ff6BAh23r9Qs4ONftp8Q VsekxpkH+P9ZVEP1EkWumhPX09UMuELvQ2qme+jUyYqHkQziniEbU9IcfazVkBoOuy6V /BWPL7+I1MgneHL03lxQmmNAJM6GF3fOqPLOFb/rXvN27uQjtp0+otn2A290SW4D0ack +qWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VwhSiUXb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m3si7882133iop.20.2021.09.23.16.11.08; Thu, 23 Sep 2021 16:11:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VwhSiUXb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243531AbhIWXLR (ORCPT + 99 others); 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