Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp945285pxb; Wed, 29 Sep 2021 13:09:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxi/IcA+A+ArBKRZOv9NJiGhFYRl9bA+jgyWfPXm2F0240/LqjFlUjnyX39taENaHq8cMhg X-Received: by 2002:a17:902:6e02:b0:13a:41f5:1666 with SMTP id u2-20020a1709026e0200b0013a41f51666mr1648515plk.39.1632946183439; Wed, 29 Sep 2021 13:09:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632946183; cv=none; d=google.com; s=arc-20160816; b=L0QXEfDn57zJbosuTmocNkZMai4L0r8XsDk7yrZ3i8CcSxSWy15poi7qwLi5KMKkIY HlUSfJ6Q5fHNHHqGjvKgPR3B6scgWoRI8fvxTYDmGNMt/Ei5bagMZmbGFXBvp+QNTCJw mSWLxlHA1mNafkO9iM2LvAtgf482De0WSZ1TKC2Fkr8m96zxkp4/Ru/WiwLQXDoMwzZ+ Kkfqj+9eSvp32QNsLi3lcv2iWxfOXr1hnJzLdl373wIIxxqv5XZjExDTgps6WBcB+95S xy85LcS2zm+nIsRyHCf+c8wwq9XiYh1QkZIiJhggcbl66TFMQxpjcaH1pG25rmL6nkxh bw0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=tlsVknWTVdSlZTHHBhOHbdQ8+OQgty9cJuZLKmK8P4Q=; b=0H8xrBdoj/UhlUMYXPB7mDgYEcbWvQIf296EpKXGyXap8GX4NP3osusSN8SW3lIg12 YCtJ5gSK1paYsdRgjHfoiHhQVOsLo/f1U7bdfiMy1Q0ZqW6UvbUD06oQgAZ+U6y/L8z7 ppA28et/mtspFQIgFFR8UIXXguyxMY6zsZR4MrPZRKS81oXnRX6MM36ZWzTLSG8kINCM 0zUGsXi4A+39OKTXFvPJDFyWpIG4YFaWKD8+JZYpwHzWyCoa5qVkduJBjzn5THW4AgvW Tk5WQP9W3wc2Xm3ABBEMkyEfGsFK/rwkfKFL+s2SznUv5CAvgv/TIuN1uHN82NP3ZUmh 9aVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=gvDSGy6E; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g3si2492377pjc.130.2021.09.29.13.09.26; Wed, 29 Sep 2021 13:09:43 -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=@linutronix.de header.s=2020 header.b=gvDSGy6E; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346413AbhI2UI6 (ORCPT + 99 others); Wed, 29 Sep 2021 16:08:58 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:45192 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346400AbhI2UIs (ORCPT ); Wed, 29 Sep 2021 16:08:48 -0400 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1632946025; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=tlsVknWTVdSlZTHHBhOHbdQ8+OQgty9cJuZLKmK8P4Q=; b=gvDSGy6EoQ/SGIQIZFDmJHsfEB7eJkkPqMOISO+qHnFj07TZ3W58Un23BsrO2SJOP5oI/M aJO6guQUBAH8/Bk3qH6nN/ewix1KG2QJPceX0aA6/YB23G/6szPYeahrHYodGiUTa4sJw3 /FZWsXw6mEh7VhBM6VWjUtpfmJ1MyBQ8gH/Kr4jh+xX9i1jTFxiEtMvT5ITfqV2Zdl2iut hDO+T4lF0i5fNNlgiuPwCsI0IT4sX4rI8ZFOy5cT5/HIqRV+vFvuNtSUEuzm/YJTXjGs+b b7pZjQr/eDgA9a/2lygRLPEDQUzWaXs9+DASg2sA1gUEIKFp2AwCtM3qayMPgA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1632946025; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=tlsVknWTVdSlZTHHBhOHbdQ8+OQgty9cJuZLKmK8P4Q=; b=icQDdrktOulCIkwKp/cwu1bpceb+vYu4ltjmHgN1zZFbMrIXdWbqAISaG/oKDVP8Nru7Uq HTEWYV63v6AU54Cg== To: "Luck, Tony" , Fenghua Yu Cc: Andy Lutomirski , Peter Zijlstra , Ingo Molnar , Borislav Petkov , Dave Hansen , Lu Baolu , Joerg Roedel , Josh Poimboeuf , Dave Jiang , Jacob Jun Pan , Raj Ashok , "Shankar, Ravi V" , 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 In-Reply-To: References: <87o88jfajo.ffs@tglx> <87k0j6dsdn.ffs@tglx> <87r1d78t2e.ffs@tglx> <75e95acc-6730-ddcf-d722-66e575076256@kernel.org> <877dez8fqu.ffs@tglx> Date: Wed, 29 Sep 2021 22:07:04 +0200 Message-ID: <874ka387tj.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 29 2021 at 11:31, Tony Luck wrote: > diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c > index a58800973aed..5a3c87fd65de 100644 > --- a/arch/x86/kernel/traps.c > +++ b/arch/x86/kernel/traps.c > @@ -528,6 +528,32 @@ static enum kernel_gp_hint get_kernel_gp_address(struct pt_regs *regs, > > #define GPFSTR "general protection fault" > > +/* > + * When a user executes the ENQCMD instruction it will #GP > + * fault if the IA32_PASID MSR has not been set up with a > + * valid PASID. > + * So if the process has been allocated a PASID (mm->pasid) > + * AND the IA32_PASID MSR has not been initialized, try to > + * fix this #GP by initializing the IA32_PASID MSR. > + * If the #GP was for some other reason, it will trigger > + * again, but this routine will return false and the #GP > + * will be processed. > + */ > +static void try_fixup_pasid(void) > +{ > + if (!cpu_feature_enabled(X86_FEATURE_ENQCMD)) > + return false; > + > +#ifdef CONFIG_IOMMU_SUPPORT > + if (current->mm->pasid && !current->pasid_activated) { > + current->pasid_activated = 1; > + wrmsrl(MSR_IA32_PASID, current->mm->pasid); > + return true; > + } > +#endif > + return false; > +} > + > DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) > { > char desc[sizeof(GPFSTR) + 50 + 2*sizeof(unsigned long) + 1] = GPFSTR; > @@ -536,6 +562,9 @@ DEFINE_IDTENTRY_ERRORCODE(exc_general_protection) > unsigned long gp_addr; > int ret; > > + if (user_mode(regs) && try_fixup_pasid()) > + return; > + > cond_local_irq_enable(regs); > > if (static_cpu_has(X86_FEATURE_UMIP)) { Amen.