Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9599503ybi; Wed, 10 Jul 2019 13:14:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqzUqQaSyPg/XAYxaytXx6IC4e82EAM3CC62AofwTZjmTD4r9hzAptc38qshcE4AusxuFz X-Received: by 2002:a17:902:b70e:: with SMTP id d14mr37600pls.309.1562789675463; Wed, 10 Jul 2019 13:14:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562789675; cv=none; d=google.com; s=arc-20160816; b=PnmINbhR6G8FLTnrG+hfBpG/clnOuOzr9+v0fSDcSQ/6B05ILmdB01DIitVzkikDfD uLlZrq7PvWC4yAXhptdWU5dwX7YMWwFW5KAkRHko42IriVn0XeZy2QVy3MLO8wDMKg5P pXMqX5epCZ+CKzbWq7l3OGnN3Z9ApI/D8lHABSyMCTJglKP7bqLojL4/k8T4TLTydipf Fkxo5IZQ/6swKKgqcNE/bb80vlj5HG1CPBLyFad0Jz0zJL9fqvbAWmGGugKKbmUfjgyl Xf1y2E3rkYrhWSdZUmDZRmdiuMVtaRzO1jzFUBzGWmiEzJy7B/a0YHNrjJMUvcSHjNHk aWow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Z/YeB5rzfyGHi9UbIOSe9nW28qqyKZ2+XgjqKHbWPpY=; b=BGzwbzZdbRIYd/U8P9uv9MDiBEpOR8GeL8QPriv1iqtKSTQxWEk2KbscceSm+qLGEP g6xlz9ORfgyQbxbKqzTM3QsDG/WULj4Rke6JXLUCjHV2XqeGnTmXGQ0IV07Q9U02WBel +D/FxuyCVz0a5hhM66R4ZCwZfzFlzbfYa/eGKQVItkySlqntnr9ZE/Z+tQiMVs01SsTU 4JS1o/NGCdiwO6wLtDBK7LoEsrgjw1enrW59D4SdZ3xIiSYYBdrsPiQfg1wWSnqZBan/ eYJXPK5yi/l0fw8/pEsTKUB3TCXqFY1KMpvFmCjVNLy6Wf2vOrmonjTg1hJM/yoF1DCC DYJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=SF+ZWihV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q1si2968033pgv.58.2019.07.10.13.14.19; Wed, 10 Jul 2019 13:14:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=SF+ZWihV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728172AbfGJUDH (ORCPT + 99 others); Wed, 10 Jul 2019 16:03:07 -0400 Received: from merlin.infradead.org ([205.233.59.134]:50338 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727595AbfGJUDH (ORCPT ); Wed, 10 Jul 2019 16:03:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Z/YeB5rzfyGHi9UbIOSe9nW28qqyKZ2+XgjqKHbWPpY=; b=SF+ZWihV7gVH3A8wgb59tzPkK jzf3LT2Tiv6jNZUbLxrNatKS9a/JTDlU3E6OzcfCmYQK+dGCNMBx14xeV59LDOtifpXygvaGWKzoh Gn8YeaLJJZLxvo12FFzmchU8cG48jo1fV9XybH5X3Iiq09TNmQphb17eLZRGbmA7o5mzbBt9RZ4Gk NJ5xC3fMAhKspzVhAqarnhysP1ygPJxZR0XYtZB2hxSRjG2wJNzBCOZZ7TsobI4iTzQ1oarqdlTSO DgxNGgAWUatz5Zq7h6Yk0yMPQU6vV9euCWX/GofR91dqBDerZZzufxkwgOhKqABrhFi6FITE6FQ2h LxExBW2OA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hlInb-0007ff-1X; Wed, 10 Jul 2019 20:02:43 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5E3E52012354A; Wed, 10 Jul 2019 22:02:40 +0200 (CEST) Date: Wed, 10 Jul 2019 22:02:40 +0200 From: Peter Zijlstra To: Thomas Gleixner Cc: Xi Ruoyao , Jiri Kosina , Kees Cook , Linus Torvalds , Ingo Molnar , Linux List Kernel Mailing , Borislav Petkov , Len Brown , Andrew Morton , "Rafael J. Wysocki" , Tony Luck , Bob Moore , Erik Schmauss , Josh Poimboeuf , Daniel Bristot de Oliveira , Juergen Gross Subject: Re: [PATCH] x86/asm: Move native_write_cr0/3() out of line Message-ID: <20190710200240.GR3402@hirez.programming.kicks-ass.net> References: <768463eb26a2feb0fcc374fd7f9cc28b96976917.camel@mengyan1223.wang> <20190710134433.GN3402@hirez.programming.kicks-ass.net> <20190710142653.GJ3419@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 10, 2019 at 09:42:46PM +0200, Thomas Gleixner wrote: > The pinning of sensitive CR0 and CR4 bits caused a boot crash when loading > the kvm_intel module on a kernel compiled with CONFIG_PARAVIRT=n. > > The reason is that the static key which controls the pinning is marked RO > after init. The kvm_intel module contains a CR4 write which requires to > update the static key entry list. That obviously does not work when the key > is in a RO section. > > With CONFIG_PARAVIRT enabled this does not happen because the CR4 write > uses the paravirt indirection and the actual write function is built in. > > As the key is intended to be immutable after init, move > native_write_cr0/3() out of line. > > While at it consolidate the update of the cr4 shadow variable and store the > value right away when the pinning is initialized on a booting CPU. No point > in reading it back 20 instructions later. This allows to confine the static > key and the pinning variable to cpu/common and allows to mark them static. > > Fixes: 8dbec27a242c ("x86/asm: Pin sensitive CR0 bits") > Fixes: 873d50d58f67 ("x86/asm: Pin sensitive CR4 bits") > Reported-by: Linus Torvalds > Reported-by: Xi Ruoyao > Signed-off-by: Thomas Gleixner > Tested-by: Xi Ruoyao Acked-by: Peter Zijlstra (Intel)