Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1614798ybh; Thu, 23 Jul 2020 13:26:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+spsIoXupeY3Jb81Q6pTxqyJoAFEpj/98h2MVgWCmFhLYIAApVDqG3FDu/kQg7e0dic89 X-Received: by 2002:a17:906:1b45:: with SMTP id p5mr5978166ejg.51.1595535997470; Thu, 23 Jul 2020 13:26:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595535997; cv=none; d=google.com; s=arc-20160816; b=tncsv/OkIWIvNT0vEKuRANYtwkopGuM3z6AO7ChRDK3MzSSGOu8nHJ8hSB0cLqWw6f wqSLT7pTkl+OvJnunlF6a+7CgwiEN20WvQVpzJlhO0CLc31uMIxy1YKX5wkEysVpfo73 jrVvVZeTgSb/9yIoTsGR+Kgjw67UsKRECib/My6Z1+8u+2j0Z+Wu+Lk0DCUuuFq/0uFL nUBQTdWlO1sZiNAdA12T9ywp86HGHRAUE2O554trG2A37BbRqhN1p0np5uSHNb7mgltm pXYkPJ5JrOwxaWf6v/ZZPzEGI6S0G98AnfiywX8wbvut74wElup06Lu6yTvcNj7BcvJZ vMtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:references:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=13eX65NKhTLwr4wa9nwWsPlfdutzeNj03w02PC/5rs4=; b=fm9WF77bzSRyCnZMNxIFm+6GH4kskU0BdsDFR/PSMjLAkfyThx1hrZKbf9rk6dax+9 XHVZ9mPQzjk4L4bCgWz9m0etzCCkLf1+RT0v1F80GbuQcCazFdOL9BlvWUreQRlK787E Y6ucY7VuJjvA4lne/RV6G6dzdzOCVyx3wwRhQ5CkFgSLdb5U+A1qRD8BO6f7eUhZ2vr2 Dvo5xKnbMdMQASI0dhUy32Zd9ciUtTgcE8BaCrH2avZ8U50NzPg1pl3PCY7sjWrpbTjG StT/eBUi41yrEiu00gCDP16a5g//VEin+mVrvGy/zMdqlvUR7gwa2Ie8IcGRwF3UxJlt RVgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1jhXPCQJ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n9si2651813edo.13.2020.07.23.13.26.14; Thu, 23 Jul 2020 13:26:37 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=1jhXPCQJ; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728050AbgGWUXd (ORCPT + 99 others); Thu, 23 Jul 2020 16:23:33 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:32818 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726033AbgGWUXc (ORCPT ); Thu, 23 Jul 2020 16:23:32 -0400 From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1595535810; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=13eX65NKhTLwr4wa9nwWsPlfdutzeNj03w02PC/5rs4=; b=1jhXPCQJstdH9CtCCpLyVZrksLIJXuuhxFGZnUfU+3pOZrI2KPqYgwbQ0Sm6xJAm0rqb84 MHefvsezd2XnqxVHrgIgYMxqPKxJw66D6fHc3dzQpiqG2CEqUFsp0YBLPVaaHTntLvme+H /Q8NDd4wYx6RFEtIrLe9e6gf5/SxK6E6ht8GAnl2/bGnX2DS7v/GfkzPP8deRI3nk6JNGz 27vZK5cyaZYNrHexeR5733cnor3v8w+8CWKk5ger8jF9c2FgL5I5wddjdqqVfWk25QGE2H 3ASkgTxi1JE5c3gbGfZu716QRCpJgAIHFiydJcxvc3hVBjjwb9YihZ2FZYZpkg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1595535810; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=13eX65NKhTLwr4wa9nwWsPlfdutzeNj03w02PC/5rs4=; b=MQsGZUsaQ6TJWdR6X93SMfni2qTkk1ixXSwjPCEB5I6pgQ0aMVt+vX2XZ7ErADgwbnwtgk 5MptZ2mJQ+GxetAg== To: Dave Hansen , Andy Lutomirski , Fenghua Yu Cc: Andy Lutomirski , Weiny Ira , Ingo Molnar , Borislav Petkov , Peter Zijlstra , Dave Hansen , X86 ML , Dan Williams , Vishal Verma , Andrew Morton , "open list\:DOCUMENTATION" , LKML , linux-nvdimm , Linux FS Devel , Linux-MM , "open list\:KERNEL SELFTEST FRAMEWORK" Subject: Re: [PATCH RFC V2 17/17] x86/entry: Preserve PKRS MSR across exceptions In-Reply-To: <71f0e3d8-6dfa-742d-eaa7-330b59611e2f@intel.com> References: <20200723165204.GB77434@romley-ivt3.sc.intel.com> <71f0e3d8-6dfa-742d-eaa7-330b59611e2f@intel.com> Date: Thu, 23 Jul 2020 22:23:29 +0200 Message-ID: <87ft9ivv3y.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dave Hansen writes: > On 7/23/20 10:08 AM, Andy Lutomirski wrote: >> Suppose some kernel code (a syscall or kernel thread) changes PKRS >> then takes a page fault. The page fault handler needs a fresh PKRS. >> Then the page fault handler (say a VMA=E2=80=99s .fault handler) changes >> PKRS. The we get an interrupt. The interrupt *also* needs a fresh >> PKRS and the page fault value needs to be saved somewhere. >>=20 >> So we have more than one saved value per thread, and thread_struct >> isn=E2=80=99t going to solve this problem. > > Taking a step back... This is all true only if we decide that we want > protection keys to provide protection during exceptions and interrupts. > Right now, the code supports nesting: > > kmap(foo); > kmap(bar); > kunmap(bar); > kunmap(foo); > > with a reference count. So, the nested kmap() will see the count > elevated and do nothing. Hopefully with a big fat warning if the nested map requires a different key than the outer one.