Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5633919imm; Wed, 12 Sep 2018 08:49:52 -0700 (PDT) X-Google-Smtp-Source: ANB0VdanauHkMGX+JFUcxqH5PAPPxykMHqJBh0KOsXv8J6rjdR9+smJ9FV8ADm9u5b3+us9jG9T8 X-Received: by 2002:a63:4044:: with SMTP id n65-v6mr2962552pga.90.1536767392432; Wed, 12 Sep 2018 08:49:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536767392; cv=none; d=google.com; s=arc-20160816; b=BHHbJovQvNL+3OfLGJb4YwEVeUp6a4K8WwnLS6ayh6G8T1oCOjpvnkiOIXQXvOSdp2 15hj6ACgc9V+RQMVBIC2bk7zZgQRNbTA88Zb2lA7TCqdcmHJjRzE0zro+QmmPegN8p9k 90Trjz6tTCQ/hkiZOdr2G0a3RwAdx0vQj/pMl0RT0mhEhZXdAHahOZCdKUnikyEkX9H3 6wLr/HmboXv3JgHnol23E7rfnj3hdelVxJcwddsWjVfrqrf+zpGyZjP62Hu8btwpNUBD shFqiA5A8gNH9P6w8ohhc9lJZiNtHA5AA1zYBjV5OqHoisxHTcOw8BzXGPoN7DONdT+d K1ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=JXM/xIvk6YvYOB09tAomtkIs5VEdkjrFvRtp8qDA/VE=; b=JzMaZ2nDJbpIMuNHFnrTdDCrkCxg+IuBq1Z1RFgM52nIyOzNDwm2uSfCmh+ZkixgsP 0WxmxjgL09wrQjP2BDz9EHCt7Bu/4jeXuPTbX9CzFvIRiJRwGPdIklRu00RpKNFNliGt xcEFNpv+R/w3/BHBTJolDVzk9xcMOlmDr3tA2hBqIKU2UPFVF9Z3zw/FIzncQY0/2Lip UEJqpYsLfy2dbmxiSsOI8tukNuQ9IMehKaZYfSt8k6hwtgkPMy19BiKC+071l+k5sVyw sK/VgjTGxXlV2mdxOIENE7a8oByICe/7s8OYWvssXVE7ioTy0UqLgkNPrIedNFbPXoQo wUNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=sHQKTJJN; 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 m24-v6si1422030pfk.56.2018.09.12.08.49.37; Wed, 12 Sep 2018 08:49:52 -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=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=sHQKTJJN; 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 S1727669AbeILUyJ (ORCPT + 99 others); Wed, 12 Sep 2018 16:54:09 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:33636 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726819AbeILUyJ (ORCPT ); Wed, 12 Sep 2018 16:54:09 -0400 Received: by mail-pl1-f194.google.com with SMTP id b30-v6so1187503pla.0 for ; Wed, 12 Sep 2018 08:49:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=JXM/xIvk6YvYOB09tAomtkIs5VEdkjrFvRtp8qDA/VE=; b=sHQKTJJNdLPvV/c+Xg1WVTabtYu/yqfw9EUQBb0oc+/kJaCwiugKlc0bgQZUziXkHC 5Rjvbj3rbmd/mKFHn9N+pDkv0LpwnGOt10P2yhXLRJdw2fnGB1eWI8pqnEVhQTPkTALX sUNJtov//cVReqpMRRpUXcR9bwRn2azUUn96o4CVwo0SI8RYFMSpuBy1OXhfswNNB4no DMpOlx/YqkhF/iMlCuT9DjQqbyUkAuVgeRJtaKNmxZhI4gQNHy/XZph9JERVTkT1Q7c4 0gLYZl7CUf2R+b+4s7OaUFU77sq8y8K2g8vokd0lJvmT+QFJohupsvhXoSGWGTtj75Mk 4jzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=JXM/xIvk6YvYOB09tAomtkIs5VEdkjrFvRtp8qDA/VE=; b=pjPaYx2rBhYlUO+/MZIC3+UhHWn0fJRHJ0hHXTczjFKJzVbbtY0FpX17CfIH3H8X/1 RhPYIFr5ch7HNqPUm1GkQujgaeK+u9vHttJCudU+0iZz8rkZceNxAxFexdTT7SQ+iY1q FCdkRKe522P2quTqvT4kE6b4xehqfi+qet1HvXAQ1lM6wlld+4d19eI2qc51AxcJN6OR BAimnctUaJTlIkJBEilcPlkdKzFBKl8EKmGrtbPyxzQfQjCGNfrI3OP6MapAUSROEBYl lcDYPR1KuupKCfaHlLfP96Gd7jcyDpio9XyAA+iq/MJ4KF9PcDq0U+dpvgc3qlG53Lyc tRUg== X-Gm-Message-State: APzg51AVRY0PG3izO8CQj7EE+EtE0P/eeNR5TpisQzerp1jxn/oKgBPN 7QkvqKe3HpKMVdxiwLl6L0IpfQ== X-Received: by 2002:a17:902:4601:: with SMTP id o1-v6mr3029094pld.202.1536767343590; Wed, 12 Sep 2018 08:49:03 -0700 (PDT) Received: from [192.168.0.239] (c-71-202-137-17.hsd1.ca.comcast.net. [71.202.137.17]) by smtp.gmail.com with ESMTPSA id t70-v6sm1913035pgd.54.2018.09.12.08.49.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 08:49:02 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) Subject: Re: [RFC PATCH 04/10] x86/fpu: eager switch PKRU state From: Andy Lutomirski X-Mailer: iPhone Mail (15G77) In-Reply-To: Date: Wed, 12 Sep 2018 08:49:01 -0700 Cc: Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org, x86@kernel.org, Andy Lutomirski , Paolo Bonzini , =?utf-8?Q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= , kvm@vger.kernel.org, "Jason A. Donenfeld" Content-Transfer-Encoding: quoted-printable Message-Id: <7C1494C8-C6CA-4599-A6B3-0833F358E3A2@amacapital.net> References: <20180912133353.20595-1-bigeasy@linutronix.de> <20180912133353.20595-5-bigeasy@linutronix.de> <181B4EB8-9FEB-415C-8069-192FB8A5B418@amacapital.net> To: Rik van Riel Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Sep 12, 2018, at 8:30 AM, Rik van Riel wrote: >=20 > On Wed, 2018-09-12 at 08:20 -0700, Andy Lutomirski wrote: >>>=20 >>> --- a/arch/x86/mm/pkeys.c >>> +++ b/arch/x86/mm/pkeys.c >>> @@ -18,6 +18,20 @@ >>>=20 >>> #include /* boot_cpu_has, >>> ... */ >>> #include /* >>> vma_pkey() */ >>> +#include >>> + >>> +void write_pkru(u32 pkru) >>> +{ >>> + if (!boot_cpu_has(X86_FEATURE_OSPKE)) >>> + return; >>> + >>> + current->thread.fpu.pkru =3D pkru; >>> + >>=20 >> I thought that the offset of PKRU in the xstate was fixed after boot. >=20 > You are right, it is. However, that offset would need > to be stored somewhere, and the value read every time > we wanted to read or store the PKRU value from/to the > floating point state. >=20 > I suspect that would not be any faster than keeping a > copy of the PKRU value in a known location. >=20 >> Anyway, as written, this needs a lockdep assertion that we=E2=80=99re not= >> preemptible, an explicit preempt_disable(), or a comment explaining >> why it=E2=80=99s okay if we get preempted in this function. >>=20 >>> + __fpregs_changes_begin(); >=20 > This handles the preemption disabling, see patch > 3 of the series. Sure, but the first write is *before* this. So we can be preempted with the t= wo copies of PKRU being out of sync. >=20 >>> + __fpregs_load_activate(¤t->thread.fpu, >>> smp_processor_id()); >>> + __write_pkru(pkru); >>> + __fpregs_changes_end(); >>> +} >>>=20 >>> int __execute_only_pkey(struct mm_struct *mm) >>> { >>> --=20 >>> 2.19.0 >>>=20 >>=20 >>=20 > --=20 > All Rights Reversed.