Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp90024pxb; Tue, 28 Sep 2021 16:13:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/YjICpNCpVvAx/III4tVi0Bdl/ig5FvZGRAAPEyytOTMBCwURAXyjDdvedRPtvshjt2uO X-Received: by 2002:a17:906:24d8:: with SMTP id f24mr8010397ejb.404.1632870807118; Tue, 28 Sep 2021 16:13:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632870807; cv=none; d=google.com; s=arc-20160816; b=omt0CHVd+yTrC21Qlnx7ZRo3GEFJtxhX6biMcwSscD+TjjUVuqA9Hp9MXUeeldr9+I RSbFDVkYF2nRWdlYUYv9+oNzVtZb3jp3Q72R4giSRqoppcOnm16bmJgml1FGd9qr/IJm O47vlzFFjy8E8BCh5PLK9G8IiUYiDJONgd8VKV7GuHDbII6DAh7JCR8AukVwFMB7jYMq wenioZjT3kddqWUqqPdgWxJDuSod84A65gkU22ZbfODHEMIhcUbn5wtD6geE4COoizoQ ltZVlNBTdqYZwIoUHAl1QnoM6CbUMVIE7yaKqipgfKrPBIbGUrYvE9t+YBbR2t0eKgWl CuGA== 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=UC19acCy1fD27P+LmTtR4JeP1ppk9jCUIlMUFiHOXuI=; b=CNoXBwxOtA4jCZewpEOZZAtd5vuqysLOhVt2WVmt5PuwT1olTs3s9O15C0FL81a7tg 0kS8CkgxgYoco+aCPjaze8R80NmmnR5WdtmAe0N3J4Ph41+fvyJB9LlQbsAsSE3lZNcR 77HG2Url5T/N3IGeZXsdHHSUruWai4YYSH6tujOSJM8Xu0WTC3V6qfXwUr+YsCvBk2cK CLnY7t6bcNMl1ljLmPZz/2vP0YqL306xIyinFu2pVtztBMVbYYYgU33mCrHU+eJZZZma tQi5Nl5MutWwgA5RvrG7M4gCQch1mlz4cHTE7S4qfV4m5UyyAnWpZMmIfEVaK6QulaYO eGiA== 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 g13si660083ejo.637.2021.09.28.16.13.03; Tue, 28 Sep 2021 16:13:27 -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 S243207AbhI1XM3 (ORCPT + 99 others); Tue, 28 Sep 2021 19:12:29 -0400 Received: from mga09.intel.com ([134.134.136.24]:65166 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243196AbhI1XMV (ORCPT ); Tue, 28 Sep 2021 19:12:21 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10121"; a="224862672" X-IronPort-AV: E=Sophos;i="5.85,330,1624345200"; d="scan'208";a="224862672" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2021 16:10:41 -0700 X-IronPort-AV: E=Sophos;i="5.85,330,1624345200"; d="scan'208";a="478985758" Received: from agluck-desk2.sc.intel.com (HELO agluck-desk2.amr.corp.intel.com) ([10.3.52.146]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2021 16:10:41 -0700 Date: Tue, 28 Sep 2021 16:10:39 -0700 From: "Luck, Tony" To: Dave Hansen Cc: Andy Lutomirski , Fenghua Yu , 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 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); 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); fpregs_unlock(); } ---- -Tony