From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37106 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751027AbeECOhk (ORCPT ); Thu, 3 May 2018 10:37:40 -0400 Subject: Re: [PATCH] pkeys: Introduce PKEY_ALLOC_SIGNALINHERIT and change signal semantics References: <20180502132751.05B9F401F3041@oldenburg.str.redhat.com> <248faadb-e484-806f-1485-c34a72a9ca0b@intel.com> <822a28c9-5405-68c2-11bf-0c282887466d@redhat.com> <57459C6F-C8BA-4E2D-99BA-64F35C11FC05@amacapital.net> <6286ba0a-7e09-b4ec-e31f-bd091f5940ff@redhat.com> From: Florian Weimer Message-ID: <74eec76a-3587-7ff6-fa0b-d8aa78ab28a1@redhat.com> Date: Thu, 3 May 2018 16:37:37 +0200 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-arch-owner@vger.kernel.org List-ID: To: Andy Lutomirski Cc: Dave Hansen , Linux-MM , Linux API , linux-x86_64@vger.kernel.org, linux-arch , X86 ML , linuxram@us.ibm.com On 05/02/2018 11:23 PM, Andy Lutomirski wrote: >> The kernel could do*something*, probably along the membarrier system >> call. I mean, I could implement a reasonable close approximation in >> userspace, via the setxid mechanism in glibc (but I really don't want to). > I beg to differ. > > Thread A: > old = RDPKRU(); > WRPKRU(old & ~3); > ... > WRPKRU(old); > > Thread B: > pkey_alloc(). > > If pkey_alloc() happens while thread A is in the ... part, you lose. It > makes no difference what the kernel does. The problem is that the WRPKRU > instruction itself is designed incorrectly. Even that is solvable, as long as the architecture as exact traps: You can look at the program counter and patch up the registers accordingly if the code is in the critical section. Of course, this would need centralizing PKRU updates in a vDSO or a single (glibc) library function. Certainly not nice and even horrible enough not to do it, but I don't think it's actually impossible. Didn't we discuss this before? Thanks, Florian