All of lore.kernel.org
 help / color / mirror / Atom feed
From: yanteng si <siyanteng01@gmail.com>
To: "Wu X.C." <bobwxc@email.cn>
Cc: Yanteng Si <siyanteng@loongson.cn>,
	Jonathan Corbet <corbet@lwn.net>, Alex Shi <alexs@kernel.org>,
	Alex Shi <seakeel@gmail.com>, Huacai Chen <chenhuacai@kernel.org>,
	Jiaxun Yang <jiaxun.yang@flygoat.com>,
	linux-doc@vger.kernel.org, Puyu Wang <realpuyuwang@gmail.com>
Subject: Re: [PATCH 2/2] docs/zh_CN: add core api protection keys translation
Date: Tue, 22 Jun 2021 21:47:59 +0800	[thread overview]
Message-ID: <CAEensMx00b1tENuHmzfY+UeYRJYvvvYc0qkcZgzfttCLARuiQA@mail.gmail.com> (raw)
In-Reply-To: <20210620043304.GA14958@bobwxc.top>

Wu X.C. <bobwxc@email.cn> 于2021年6月20日周日 下午12:33写道:
>
> On Tue, Jun 15, 2021 at 03:52:40PM +0800, Yanteng Si wrote:
> > Translate Documentation/core-api/protection-keys.rst into Chinese.
> >
> > Signed-off-by: Yanteng Si <siyanteng@loongson.cn>
> > ---
> >  .../zh_CN/core-api/protection-keys.rst        | 98 +++++++++++++++++++
> >  1 file changed, 98 insertions(+)
> >  create mode 100644 Documentation/translations/zh_CN/core-api/protection-keys.rst
> >
> > diff --git a/Documentation/translations/zh_CN/core-api/protection-keys.rst b/Documentation/translations/zh_CN/core-api/protection-keys.rst
> > new file mode 100644
> > index 000000000000..91a282b9a576
> > --- /dev/null
> > +++ b/Documentation/translations/zh_CN/core-api/protection-keys.rst
> > @@ -0,0 +1,98 @@
> > +.. SPDX-License-Identifier: GPL-2.0
> > +.. include:: ../disclaimer-zh_CN.rst
> > +
> > +:Original: Documentation/core-api/protection-keys.rst
> > +
> > +:翻译:
> > +
> > + 司延腾 Yanteng Si <siyanteng@loongson.cn>
> > +
> > +:校译:
> > +
> > +
> > +.. _cn_core-api_protection-keys:
> > +
> > +============
> > +内存保护密钥
> > +============
> > +
> > +用户空间的内存保护密钥(PKU,又称PKEYs)是英特尔Skylake(及以后)"可扩
>                                                                     ^
> (Memory Protection Keys for Userspace,PKU,亦即PKEYs)
ok
>
> > +展处理器 "服务器CPU上的一项功能。它将在未来的非服务器英特尔处理器和未来
>            ^^
>            “”
ok
>
> > +的AMD处理器中使用。
>
> s/使用/可用/
ok
>
> > +
> > +对于任何希望测试或使用该功能的人来说,它在亚马逊的EC2 C5实例中是可用的,
> > +并且已知可以在那里使用Ubuntu 17.04镜像运行。
> > +
> > +内存保护密钥提供了一种机制来执行基于页面的保护,但在应用程序改变保护域
> > +时不需要修改页表。它的工作原理是在每个页表项中为 "保护密钥 "分配4个以
>                                                    ^^        ^^
ok
>
> > +前被忽略的位,从而提供16个可能的密钥。
> > +
> > +还有一个新的用户可访问的寄存器(PKRU),为每个密钥提供两个单独的位(访
>                          ^^
>                          remove 的
>                          断句歧义
ok,removed
>
> > +问禁止和写入禁止)。作为一个CPU寄存器,PKRU在本质上是线程本地的,可能
> > +会给每个线程提供一套不同于其他线程的保护措施。
> > +
> > +有两条新指令(RDPKRU/WRPKRU)用于读取和写入新的寄存器。该功能仅在64位
> > +模式下可用,尽管PAE PTEs中理论上有空间。这些权限只在数据访问上强制执行,
> > +对指令获取没有影响。
>
> s/PAE PTEs/物理地址扩展页表/ ?
ok
>
> > +
> > +
> > +系统调用
> > +========
> > +
> > +有3个系统调用可以直接与pkeys进行交互::
> > +
> > +     int pkey_alloc(unsigned long flags, unsigned long init_access_rights)
> > +     int pkey_free(int pkey);
> > +     int pkey_mprotect(unsigned long start, size_t len,
> > +                       unsigned long prot, int pkey);
> > +
> > +在使用一个pkey之前,必须先用pkey_alloc()分配它。一个应用程序直接调用
> > +WRPKRU指令,以改变一个密钥覆盖的内存的访问权限。在这个例子中,WRPKRU
> > +被一个叫做pkey_set()的C函数所封装::
> > +
> > +     int real_prot = PROT_READ|PROT_WRITE;
> > +     pkey = pkey_alloc(0, PKEY_DISABLE_WRITE);
> > +     ptr = mmap(NULL, PAGE_SIZE, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
> > +     ret = pkey_mprotect(ptr, PAGE_SIZE, real_prot, pkey);
> > +     ... application runs here
> > +
> > +现在,如果应用程序需要更新'ptr'处的数据,它可以获得访问权,进行更新,
> > +然后取消其写访问权::
> > +
> > +     pkey_set(pkey, 0); // clear PKEY_DISABLE_WRITE
> > +     *ptr = foo; // assign something
> > +     pkey_set(pkey, PKEY_DISABLE_WRITE); // set PKEY_DISABLE_WRITE again
> > +
> > +现在,当它释放内存时,它也将释放pkey,因为它不再被使用了::
> > +
> > +     munmap(ptr, PAGE_SIZE);
> > +     pkey_free(pkey);
> > +
> > +.. note:: pkey_set()是RDPKRU和WRPKRU指令的一个封装器。在tools/testing/selftests/x86/protection_keys.c中可以找到一个实现实例。
> > +          tools/testing/selftests/x86/protection_keys.c.
> > +
> > +行为
> > +====
> > +
> > +内核试图使保护密钥与普通的protect()的行为一致。例如,如果你这样做::
>                              ^^^^^^^^^
>
ok,
>
> > +
> > +     mprotect(ptr, size, PROT_NONE);
> > +     something(ptr);
> > +
> > +这样做的时候,你可以期待保护密钥的相同效果::
> > +
> > +     pkey = pkey_alloc(0, PKEY_DISABLE_WRITE | PKEY_DISABLE_READ);
> > +     pkey_mprotect(ptr, size, PROT_READ|PROT_WRITE, pkey);
> > +     something(ptr);
> > +
> > +无论something()是否是对'ptr'的直接访问,这都应该为真。
> > +如::
> > +
> > +     *ptr = foo;
> > +
> > +或者当内核代表应用程序进行访问时,比如read()::
> > +
> > +     read(fd, ptr, 1);
> > +
> > +在这两种情况下,内核都会发送一个SIGSEGV,但当违反保护密钥时,si_code
> > +将被设置为SEGV_PKERR,而当违反普通的mprotect()权限时,则是SEGV_ACCERR。
> > --
> > 2.27.0
>
> Thanks,
>         Wu X.C.
Thanks you for your review!

Thanks,

Yanteng

      reply	other threads:[~2021-06-22 13:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-15  7:52 [PATCH 0/2] docs/core-api: add memory_hotplug and protection keys translation Yanteng Si
2021-06-15  7:52 ` [PATCH 1/2] docs/zh_CN: add core api memory_hotplug translation Yanteng Si
2021-06-17  7:48   ` Wu X.C.
2021-06-19  2:07     ` yanteng si
2021-06-15  7:52 ` [PATCH 2/2] docs/zh_CN: add core api protection keys translation Yanteng Si
2021-06-20  4:33   ` Wu X.C.
2021-06-22 13:47     ` yanteng si [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEensMx00b1tENuHmzfY+UeYRJYvvvYc0qkcZgzfttCLARuiQA@mail.gmail.com \
    --to=siyanteng01@gmail.com \
    --cc=alexs@kernel.org \
    --cc=bobwxc@email.cn \
    --cc=chenhuacai@kernel.org \
    --cc=corbet@lwn.net \
    --cc=jiaxun.yang@flygoat.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=realpuyuwang@gmail.com \
    --cc=seakeel@gmail.com \
    --cc=siyanteng@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.