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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5F4CC4332F for ; Fri, 24 Sep 2021 15:39:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F60D61241 for ; Fri, 24 Sep 2021 15:39:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347273AbhIXPlJ (ORCPT ); Fri, 24 Sep 2021 11:41:09 -0400 Received: from mga07.intel.com ([134.134.136.100]:16216 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347246AbhIXPlE (ORCPT ); Fri, 24 Sep 2021 11:41:04 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10116"; a="287766991" X-IronPort-AV: E=Sophos;i="5.85,320,1624345200"; d="scan'208";a="287766991" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Sep 2021 08:39:30 -0700 X-IronPort-AV: E=Sophos;i="5.85,320,1624345200"; d="scan'208";a="551854501" Received: from agluck-desk2.sc.intel.com (HELO agluck-desk2.amr.corp.intel.com) ([10.3.52.146]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Sep 2021 08:39:28 -0700 Date: Fri, 24 Sep 2021 08:39:24 -0700 From: "Luck, Tony" To: Peter Zijlstra Cc: Fenghua Yu , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Dave Hansen , Lu Baolu , Joerg Roedel , Josh Poimboeuf , Dave Jiang , Jacob Jun Pan , Ashok Raj , Ravi V Shankar , iommu@lists.linux-foundation.org, x86 , linux-kernel Subject: Re: [PATCH 4/8] x86/traps: Demand-populate PASID MSR via #GP Message-ID: References: <20210920192349.2602141-1-fenghua.yu@intel.com> <20210920192349.2602141-5-fenghua.yu@intel.com> <20210922210722.GV4323@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 24, 2021 at 03:37:22PM +0200, Peter Zijlstra wrote: > On Thu, Sep 23, 2021 at 10:14:42AM -0700, Luck, Tony wrote: > > On Wed, Sep 22, 2021 at 11:07:22PM +0200, Peter Zijlstra wrote: > > > On Mon, Sep 20, 2021 at 07:23:45PM +0000, Fenghua Yu wrote: > > > > @@ -538,6 +547,9 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) > > > > > > > > cond_local_irq_enable(regs); > > > > > > > > + if (user_mode(regs) && fixup_pasid_exception()) > > > > + goto exit; > > > > + > > > > > So you're eating any random #GP that might or might not be PASID > > > related. And all that witout a comment... Enlighten? > > > > This is moderately well commented inside the fixup_pasid_exception() > > function. Another copy of the comments here at the call-site seems > > overkill. > > +static bool fixup_pasid_exception(void) > +{ > + if (!cpu_feature_enabled(X86_FEATURE_ENQCMD)) > + return false; > + > + return __fixup_pasid_exception(); > +} > > /me goes looking for comments in that function, lemme get out the > electron microscope, because I can't seem to spot them with the naked > eye. If you have ctags installed then a ctrl-] on that __fixup_pasid_exception() will take you to the function with the comments. No electron microscope needed. + +/* + * Try to figure out if there is a PASID MSR value to propagate to the + * thread taking the #GP. + */ +bool __fixup_pasid_exception(void) +{ + u32 pasid; + + /* + * This function is called only when this #GP was triggered from user + * space. So the mm cannot be NULL. + */ + pasid = current->mm->pasid; + + /* If no PASID is allocated, there is nothing to propagate. */ + if (pasid == PASID_DISABLED) + return false; + + /* + * If the current task already has a valid PASID MSR, then the #GP + * fault must be for some non-ENQCMD related reason. + */ + if (current->has_valid_pasid) + return false; + + /* Fix up the MSR by the PASID in the mm. */ + fpu__pasid_write(pasid); + current->has_valid_pasid = 1; + + return true; +} -Tony