Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4189737pxj; Tue, 15 Jun 2021 17:54:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyedVO2pqdqWz/Hrk8BEAzWRws3L9GQRkmod0bzKKxNG8ha0aYj6JLjfidKguUP0OW+PoTa X-Received: by 2002:a17:906:f19a:: with SMTP id gs26mr2311419ejb.551.1623804841544; Tue, 15 Jun 2021 17:54:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623804841; cv=none; d=google.com; s=arc-20160816; b=pg62tJW0I4AXb12WS+yI3z+8ThZcWkrIad7oGaZL02dEic4YxR5BzNrXi9Qpjt/z6H Mz7Qj7O/nCMcUrmYY6JZSexbvtgzx9SDoAJoEavoB6f5HjenQCgIz9wQPwQb6i/tiHm1 e0DRekpDaG8rJFO9SQzupQgHX27+xViydPrtqYuqi5j1g4MEDeN8pbm/YYg7tfMZzdq+ iNpCjcMmnPzZDQgR0ecUY/ur9dmxZ4Ds6JvXmkBbnf9p4EmhjQjYJZr0w/einWMDRXvc xw1vwzg7fLrwSbqZCoeltGDKQZRaDwJnQFT7ZQah58rss2cXlxJyvsIRQMoW3cfNKs5A QD2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:ironport-sdr:ironport-sdr; bh=RzgAkJqc0sOKhgxPs2sJoG5hAHOl/mBhn1YdXpNLSs4=; b=wFwqNtbBwWu4f/MFcFJs7J+r66xLcXoIdTC3uIFxrH0ob1dET5LUlGM29NPz+uCI5/ mANspdVJ9Du+kdbQLFPMGBOjhwMWqAw0vNrFnUrI7RVn0S40AqPITdJKQaoObvuRrC9+ qN0H0I4f4vDzOOkRfxgFK2P0lMaLXtZnAGwZb7SplCnc6ObKr0EQz2JgrTiZW3uvrevU BtmquEi53BhjwadVrA1LxH3PTqr9m1V3mBOCJavGkyz5MI/aiH5W3I4vAntQveu/8Msv 2eprCUg2fCcFOPBNkmE33gMoLJY9i8eZUFqQcXgwoPLyelF7ZVRQehxZMhEy6fJSwwNu 36lg== 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 z13si670715ejl.2.2021.06.15.17.53.39; Tue, 15 Jun 2021 17:54:01 -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 S231770AbhFPAyi (ORCPT + 99 others); Tue, 15 Jun 2021 20:54:38 -0400 Received: from mga03.intel.com ([134.134.136.65]:16036 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230507AbhFPAyi (ORCPT ); Tue, 15 Jun 2021 20:54:38 -0400 IronPort-SDR: E/RxdiNnr9GWIYyYi2Dkywy7DaFJxpd7egGjJ8HT4MvYHjl9psvLaVE0PUCq5kDU4F4chFC/CC nMdYo1sMy3XA== X-IronPort-AV: E=McAfee;i="6200,9189,10016"; a="206130665" X-IronPort-AV: E=Sophos;i="5.83,276,1616482800"; d="scan'208";a="206130665" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2021 17:52:33 -0700 IronPort-SDR: 5ODhYNMSOO5iPrbRyknXuV4poigcgPtanE2G3rKPno2jxZqBBlk/hKrI9+14DfWUx9W+b5feUR VfkUAVE1VmIA== X-IronPort-AV: E=Sophos;i="5.83,276,1616482800"; d="scan'208";a="452154021" Received: from yyu32-mobl1.amr.corp.intel.com (HELO [10.212.5.156]) ([10.212.5.156]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2021 17:52:32 -0700 Subject: Re: [patch V2 45/52] x86/fpu: Dont restore PKRU in fpregs_restore_userspace() To: Thomas Gleixner , LKML Cc: Andy Lutomirski , Dave Hansen , Fenghua Yu , Tony Luck , Sebastian Andrzej Siewior , Borislav Petkov , Peter Zijlstra , Kan Liang References: <20210614154408.673478623@linutronix.de> <20210614155358.277290739@linutronix.de> From: "Yu, Yu-cheng" Message-ID: <89da2d23-7de8-8dee-5b6a-361b7ceeae8e@intel.com> Date: Tue, 15 Jun 2021 17:52:32 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210614155358.277290739@linutronix.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/14/2021 8:44 AM, Thomas Gleixner wrote: > switch_to(), flush_thread() write the task's PKRU value eagerly so the PKRU > value of current is always valid in the hardware. > > That means there is no point in restoring PKRU on exit to user or when > reactivating the task's FPU registers in the signal frame setup path. > > This allows to remove all the xstate buffer updates with PKRU values once > the PKRU state is stored in thread struct while a task is scheduled out. > > Signed-off-by: Thomas Gleixner > --- > arch/x86/include/asm/fpu/internal.h | 12 +++++++++++- > arch/x86/include/asm/fpu/xstate.h | 19 +++++++++++++++++++ > arch/x86/kernel/fpu/core.c | 2 +- > 3 files changed, 31 insertions(+), 2 deletions(-) > > --- a/arch/x86/include/asm/fpu/internal.h > +++ b/arch/x86/include/asm/fpu/internal.h > @@ -455,7 +455,17 @@ static inline void fpregs_restore_userre > return; > > if (!fpregs_state_valid(fpu, cpu)) { > - restore_fpregs_from_fpstate(&fpu->state); > + /* > + * This restores _all_ xstate which has not been > + * established yet. > + * > + * If PKRU is enabled, then the PKRU value is already > + * correct because it was either set in switch_to() or in > + * flush_thread(). So it is excluded because it might be > + * not up to date in current->thread.fpu.xsave state. > + */ > + __restore_fpregs_from_fpstate(&fpu->state, > + xfeatures_mask_restore_user()); This needs to be xfeatures_mask_restore_user() | xfeatures_mask_supervisor(). > fpregs_activate(fpu); > fpu->last_cpu = cpu; > } [...]