Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp115215pxb; Tue, 28 Sep 2021 16:55:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwe2GqF/ErBgLxhwexizfDHZcDtvtm9E1Bq1C3P3PVfDJorWjho0pJWC8qruXxDmMUEBmCG X-Received: by 2002:a50:9d0f:: with SMTP id v15mr11284428ede.275.1632873345706; Tue, 28 Sep 2021 16:55:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632873345; cv=none; d=google.com; s=arc-20160816; b=rXTDrw2S6nyctj6Rj6pd85YxcdrV3Np952xrN9f1+lDpjWHV+gCPhBVVXzzdm50BK4 qdu16OPngYcL06lRB1dNOafh/i3e8QISkEpa48YE4c8MQz2rZUTt1lVtT+aW6L2WASE5 zNNTUwB5yTGRimd5NTJc8QSVPyy/v6urb42anCqJ0+1F/eOWjjcpvrBDvCOLSvtTU4VH IPVUh2qwKtrHtEjk1PoXy9pmr7rM7a2NE9gQv0uAo/TSTN6wiEfvIsjQXmxcZ3cipPlX PAGxzTxmfCc3OdFP0Hk73SjPpDBhcO6A0wtAPOKUc0KYRioX05ebZjqGLrOwHxJqNeGC MgIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=C3aSp/4WyglyBxfKHZ7w0PXeMij8HUxc60S8wzbGOeM=; b=UANFQd+BVyvs7RtKIQVLFR6jZOqPkcSFifESSQwjv98YJk1QvNbFux4s3USXRRBxSo lRh7kAQ5wr31GDf6aKUdjCuinbntCR7dbkeJnnicT+CE7jCNCSQE8bx7yIqyLc1jkR6m ZVeM18nUjc9xZZ+ZsDeZkHSnXsVG599ufTAm6HcpzXvL2v+5seo/ObBe/UEXkTnmQAU6 0gB/GCj5AMhh7Efb1mh+K4EvyGEq4wSgj1IijxRXYIKZ0zC6wKakbOXNwYZoZb/33Jkp MAHY/n1OMm+iEOuPQBr6go/H2Neq5NTkTqWXEVOnTtejWqv1UkkiQGYp75P2I/S+JWtJ wQQw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r16si571398edy.214.2021.09.28.16.55.07; Tue, 28 Sep 2021 16:55:45 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243235AbhI1XwZ (ORCPT + 99 others); Tue, 28 Sep 2021 19:52:25 -0400 Received: from mga05.intel.com ([192.55.52.43]:50768 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242094AbhI1XwY (ORCPT ); Tue, 28 Sep 2021 19:52:24 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10121"; a="310377417" X-IronPort-AV: E=Sophos;i="5.85,330,1624345200"; d="scan'208";a="310377417" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2021 16:50:44 -0700 X-IronPort-AV: E=Sophos;i="5.85,330,1624345200"; d="scan'208";a="538605950" Received: from otcwcpicx3.sc.intel.com ([172.25.55.73]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2021 16:50:44 -0700 Date: Tue, 28 Sep 2021 23:50:37 +0000 From: Fenghua Yu To: "Luck, Tony" Cc: Dave Hansen , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "Peter Zijlstra (Intel)" , 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 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> <1aae375d-3cd4-4ab8-9c64-9e387916e6c0@www.fastmail.com> <035290e6-d914-a113-ea6c-e845d71069cf@intel.com> <3f97b77e-a609-997b-3be7-f44ff7312b0d@intel.com> 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 Hi, Tony, On Tue, Sep 28, 2021 at 04:10:39PM -0700, Luck, Tony wrote: > Moving beyond pseudo-code and into compiles-but-probably-broken-code. > > > The intent of the functions below is that Fenghua should be able to > do: > > void fpu__pasid_write(u32 pasid) > { > u64 msr_val = pasid | MSR_IA32_PASID_VALID; > struct ia32_pasid_state *addr; > > addr = begin_update_one_xsave_feature(current, XFEATURE_PASID, true); > addr->pasid = msr_val; > finish_update_one_xsave_feature(current); > } > > So here's the two new functions that would be added to > arch/x86/kernel/fpu/xstate.c > > ---- > > void *begin_update_one_xsave_feature(struct task_struct *tsk, > enum xfeature xfeature, bool full) > { > struct xregs_state *xsave = &tsk->thread.fpu.state.xsave; > struct xregs_state *xinit = &init_fpstate.xsave; > u64 fmask = 1ull << xfeature; > void *addr; > > BUG_ON(!(xsave->header.xcomp_bv & fmask)); > > fpregs_lock(); > > addr = __raw_xsave_addr(xsave, xfeature); > > if (full || tsk != current) { > memcpy(addr, __raw_xsave_addr(xinit, xfeature), xstate_sizes[xfeature]); > goto out; > } > > /* could optimize some cases where xsaves() isn't fastest option */ > if (!(xsave->header.xfeatures & fmask)) > xsaves(xsave, fmask); If xfeatures's feature bit is 0, xsaves will not write its init value to the memory due to init optimization. So the xsaves will do nothing and the state is not initialized and may have random data. > > out: > xsave->header.xfeatures |= fmask; > return addr; > } > > void finish_update_one_xsave_feature(struct task_struct *tsk) > { > set_ti_thread_flag(task_thread_info(tsk), TIF_NEED_FPU_LOAD); Setting TIF_NEED_FPU_LOAD cannot guaranteed to execute XRSTORS on exiting to user. In fpregs_restore_userregs(): if (!fpregs_state_valid(fpu, cpu)) { ... __restore_fpregs_from_fpstate(&fpu->state, mask); ... } fpregs state should be invalid to get the XRSTROS executed. So setting TIF_NEED_FPU_LOAD may get the FPU register unchanged on exiting to user. > fpregs_unlock(); > } Thanks. -Fenghua