Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6913742yba; Thu, 2 May 2019 00:13:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzuxuKnTHwhwMyuciuMg51ewYL9UR/WYiGXq/M5HU78lvxlXn4MeuN4aaqxERBXu1PTDRPs X-Received: by 2002:aa7:9089:: with SMTP id i9mr2482903pfa.115.1556781216725; Thu, 02 May 2019 00:13:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556781216; cv=none; d=google.com; s=arc-20160816; b=PFLKEFoY+2CEyL12FAKQUbbHtw66yijbZdl2u+/g38ILBTz9E9a04iEJNuZvCF3Ehr llpS7NmQ5qPXU+Vwz47iE4QJ/bg9KTiVSu6bbo4g7poHYRQ+7BP0QP1UrwMcHW/Z5Pwm ZZf6QfD1/IbptuZhD7I5unLeBel/B2pazXJBBhrUYwntgK5NpNr4ciEvxSaLJocI99vw CaU2C/d7DQ+3kofo7d4/jMS4CDwUfn6VvhaHINFZr7yrNYASZy39Wy5McBWnGbg4DIpP cJDENMa9x6ckRjvmY1xGOkcrIVrbKxEaI8Zx2xfg1E7EAbd4QPmhDf/29QjSl5El4IO/ 5apw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sp5SvL0P5lrU86BpXk5nK8V2Shd1dKoGOnP2voXWJNg=; b=r7X5IAh9iwFqoe3vcQnnLvnykgTkXeEyYtezV09LeDuChIYEeWXTVE69G7tkAfv0mm ec+iZpSRu8sx+VIwNrpNQA5M2W3pzmqv1p1ZRYd4GXuiyNjRVDitXJohvq12GB0Vzq4d +2+LUyFgTXPyDr8OyKi2ZT/lkvcQ/Fy93cda0LkbIKJ4laCWH0Io0tvdF4v9yoNPhbV3 7hHgcqgU6WBXjzKqlJPO+npXQ9Qhf/jl4dTYwL6itB+sCs7TRUjRZ+huYqcQLh/96Xau 3B3KyES4uWa7hrGx75aYGsMR8xsmeSfxTrNSDBaCx9o+pL1onno/yAzLi+abH3JVfzz6 JuSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Me9ZA0cP; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d66si712692pfa.201.2019.05.02.00.13.21; Thu, 02 May 2019 00:13:36 -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=@gmail.com header.s=20161025 header.b=Me9ZA0cP; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726685AbfEBHKt (ORCPT + 99 others); Thu, 2 May 2019 03:10:49 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:36796 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726202AbfEBHKs (ORCPT ); Thu, 2 May 2019 03:10:48 -0400 Received: by mail-pg1-f194.google.com with SMTP id 85so651890pgc.3; Thu, 02 May 2019 00:10:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sp5SvL0P5lrU86BpXk5nK8V2Shd1dKoGOnP2voXWJNg=; b=Me9ZA0cPf/JxdnQ4ZjQ6PhYMDQsy79kk9zaKmJuLcsbbIj4JGnP022I1mlvxa7gqgM wbW1K6yX8F7RoEvdHhY5c9aEnLFn/z1L4RTmvM+7k36Ctusex+6pPlWfo8wrZwd2YSIg 9SX70NBRqQIrd4vKsqkaPRoWVbm1p/Rrb7gvbGCq7DNjNZ9PMAH70/L9juKXnQNdBMLR LO3G/hioG38W6NGJpP0/ghpMcrgIUxx0i13WWoYLX00HVm2AyzUBml/oOkga43GCK9f8 fg1rkmkzUy+PbMDhInhVk0Kr3+P05+mcKaRwurGYDRQcANVpgL0nEIo1w7JlLAakY44l O9YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sp5SvL0P5lrU86BpXk5nK8V2Shd1dKoGOnP2voXWJNg=; b=fk340raZLFuK3cJ0pv8wfuFpHdr0pxf7hbUKdMLNXd6TigeJlLYWdYzrJeeLWamxpe XLxW3geKKGL0QFKtWDOjQF/PrBdf9qAJFDyGiAhr031sf2zdIv79pYs+XsED7QrjdxAj nIHpRIyiP/J/9dE51g+fY3Pcma+oXPk7cZMKnxGE0Aw6O3ahSVgViU7nbWVj7xJZ0wA/ JQGS3UNPOA1SMtcifJYX/UdUgAKn2cpeTD2dIhWl80BplxgljlyGGDMRiSL/QFnsqoPT LJJnc5Qi5jOZOeKmBgJrYBH7bBCNpmpejU0YUzh3WVQyDPcD+A6LSVuqH0mw33sT3Nby ubag== X-Gm-Message-State: APjAAAVNxtBI8zlbzlqKHFdRo+UKDkIgfuNzi+SQF/yjuKvMMG52hbOR 9MIdoorsYkdrub9XaYk3bAs= X-Received: by 2002:a65:4341:: with SMTP id k1mr2388518pgq.88.1556781047609; Thu, 02 May 2019 00:10:47 -0700 (PDT) Received: from laptop.DHCP ([104.238.181.70]) by smtp.gmail.com with ESMTPSA id u24sm4686976pfh.91.2019.05.02.00.10.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 May 2019 00:10:46 -0700 (PDT) From: Changbin Du To: corbet@lwn.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de Cc: x86@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Changbin Du , Mauro Carvalho Chehab Subject: [PATCH v2 12/27] Documentation: x86: convert protection-keys.txt to reST Date: Thu, 2 May 2019 15:06:18 +0800 Message-Id: <20190502070633.9809-13-changbin.du@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190502070633.9809-1-changbin.du@gmail.com> References: <20190502070633.9809-1-changbin.du@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This converts the plain text documentation to reStructuredText format and add it to Sphinx TOC tree. No essential content change. Signed-off-by: Changbin Du Reviewed-by: Mauro Carvalho Chehab --- Documentation/x86/index.rst | 1 + ...rotection-keys.txt => protection-keys.rst} | 33 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) rename Documentation/x86/{protection-keys.txt => protection-keys.rst} (83%) diff --git a/Documentation/x86/index.rst b/Documentation/x86/index.rst index f7012e4afacd..e2c0db9fcd4e 100644 --- a/Documentation/x86/index.rst +++ b/Documentation/x86/index.rst @@ -18,3 +18,4 @@ x86-specific Documentation tlb mtrr pat + protection-keys diff --git a/Documentation/x86/protection-keys.txt b/Documentation/x86/protection-keys.rst similarity index 83% rename from Documentation/x86/protection-keys.txt rename to Documentation/x86/protection-keys.rst index ecb0d2dadfb7..49d9833af871 100644 --- a/Documentation/x86/protection-keys.txt +++ b/Documentation/x86/protection-keys.rst @@ -1,3 +1,9 @@ +.. SPDX-License-Identifier: GPL-2.0 + +====================== +Memory Protection Keys +====================== + Memory Protection Keys for Userspace (PKU aka PKEYs) is a feature which is found on Intel's Skylake "Scalable Processor" Server CPUs. It will be avalable in future non-server parts. @@ -23,9 +29,10 @@ even though there is theoretically space in the PAE PTEs. These permissions are enforced on data access only and have no effect on instruction fetches. -=========================== Syscalls =========================== +Syscalls +======== -There are 3 system calls which directly interact with pkeys: +There are 3 system calls which directly interact with pkeys:: int pkey_alloc(unsigned long flags, unsigned long init_access_rights) int pkey_free(int pkey); @@ -37,6 +44,7 @@ pkey_alloc(). An application calls the WRPKRU instruction directly in order to change access permissions to memory covered with a key. In this example WRPKRU is wrapped by a C function called pkey_set(). +:: int real_prot = PROT_READ|PROT_WRITE; pkey = pkey_alloc(0, PKEY_DISABLE_WRITE); @@ -45,43 +53,44 @@ called pkey_set(). ... application runs here Now, if the application needs to update the data at 'ptr', it can -gain access, do the update, then remove its write access: +gain access, do the update, then remove its write access:: pkey_set(pkey, 0); // clear PKEY_DISABLE_WRITE *ptr = foo; // assign something pkey_set(pkey, PKEY_DISABLE_WRITE); // set PKEY_DISABLE_WRITE again Now when it frees the memory, it will also free the pkey since it -is no longer in use: +is no longer in use:: munmap(ptr, PAGE_SIZE); pkey_free(pkey); -(Note: pkey_set() is a wrapper for the RDPKRU and WRPKRU instructions. - An example implementation can be found in - tools/testing/selftests/x86/protection_keys.c) +.. note:: pkey_set() is a wrapper for the RDPKRU and WRPKRU instructions. + An example implementation can be found in + tools/testing/selftests/x86/protection_keys.c. -=========================== Behavior =========================== +Behavior +======== The kernel attempts to make protection keys consistent with the -behavior of a plain mprotect(). For instance if you do this: +behavior of a plain mprotect(). For instance if you do this:: mprotect(ptr, size, PROT_NONE); something(ptr); -you can expect the same effects with protection keys when doing this: +you can expect the same effects with protection keys when doing this:: pkey = pkey_alloc(0, PKEY_DISABLE_WRITE | PKEY_DISABLE_READ); pkey_mprotect(ptr, size, PROT_READ|PROT_WRITE, pkey); something(ptr); That should be true whether something() is a direct access to 'ptr' -like: +like:: *ptr = foo; or when the kernel does the access on the application's behalf like -with a read(): +with a read():: read(fd, ptr, 1); -- 2.20.1