All of lore.kernel.org
 help / color / mirror / Atom feed
From: Khalid Aziz <khalid.aziz@oracle.com>
To: Rob Gardner <rob.gardner@oracle.com>,
	davem@davemloft.net, corbet@lwn.net
Cc: viro@zeniv.linux.org.uk, nitin.m.gupta@oracle.com,
	mike.kravetz@oracle.com, akpm@linux-foundation.org,
	mingo@kernel.org, kirill.shutemov@linux.intel.com,
	adam.buchbinder@gmail.com, hughd@google.com, minchan@kernel.org,
	keescook@chromium.org, chris.hyser@oracle.com,
	atish.patra@oracle.com, cmetcalf@mellanox.com,
	atomlin@redhat.com, jslaby@suse.cz, joe@perches.com,
	paul.gortmaker@windriver.com, mhocko@suse.com,
	lstoakes@gmail.com, jack@suse.cz, dave.hansen@linux.intel.com,
	vbabka@suse.cz, dan.j.williams@intel.com, iamjoonsoo.kim@lge.com,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	sparclinux@vger.kernel.org, linux-mm@kvack.org,
	Khalid Aziz <khalid@gonehiking.org>
Subject: Re: [PATCH v5 4/4] sparc64: Add support for ADI (Application Data Integrity)
Date: Wed, 25 Jan 2017 15:57:36 -0700	[thread overview]
Message-ID: <97f5ad25-432c-f536-d2af-681288b7cca1@oracle.com> (raw)
In-Reply-To: <19f33a99-e719-a2a5-4330-390ed7755315@oracle.com>

On 01/25/2017 03:50 PM, Rob Gardner wrote:
> On 01/25/2017 03:20 PM, Khalid Aziz wrote:
>> On 01/25/2017 03:00 PM, Rob Gardner wrote:
>>> On 01/25/2017 12:57 PM, Khalid Aziz wrote:
>>>>
>>>> @@ -157,6 +158,24 @@ int __get_user_pages_fast(unsigned long start,
>>>> int nr_pages, int write,
>>>>       pgd_t *pgdp;
>>>>       int nr = 0;
>>>>   +#ifdef CONFIG_SPARC64
>>>> +    if (adi_capable()) {
>>>> +        long addr = start;
>>>> +
>>>> +        /* If userspace has passed a versioned address, kernel
>>>> +         * will not find it in the VMAs since it does not store
>>>> +         * the version tags in the list of VMAs. Storing version
>>>> +         * tags in list of VMAs is impractical since they can be
>>>> +         * changed any time from userspace without dropping into
>>>> +         * kernel. Any address search in VMAs will be done with
>>>> +         * non-versioned addresses. Ensure the ADI version bits
>>>> +         * are dropped here by sign extending the last bit before
>>>> +         * ADI bits. IOMMU does not implement version tags.
>>>> +         */
>>>> +        addr = (addr << (long)adi_nbits()) >> (long)adi_nbits();
>>>
>>>
>>> So you are depending on the sign extension to clear the ADI bits... but
>>> this only happens if there is a zero in that "last bit before ADI bits".
>>> If the last bit is a 1, then the ADI bits will be set instead of
>>> cleared.  That seems like an unintended consequence given the comment. I
>>> am aware of the value of adi_nbits() and of the number of valid bits in
>>> a virtual address on the M7 processor, but wouldn't using 'unsigned
>>> long' for everything here guarantee the ADI bits get cleared regardless
>>> of the state of the last non-adi bit?
>>
>> Sign extension is the right thing to do. MMU considers values of 0 and
>> 15 for bits 63-60 to be untagged addresses and expects bit 59 to be
>> sign-extended for untagged virtual addresses. The code I added is
>> explicitly meant to sign-extend, not zero out the top 4 bits.
>
> OK, that wasn't perfectly clear from the comment, which said "version
> bits are dropped".
>
> So sign extending will produce an address that the MMU can use, but will
> it produce an address that will allow a successful search in the page
> tables? ie, was this same sign extending done when first handing out
> that virtual address to the user?
>

Yes to both your questions. When virtual addresses are handed out, the 
last implemented virtual address bit is sign-extended. Sign-extending 
when dropping version bits preserves that original sign-extension. This 
is why MMU considers tag values of 0 as well as 15 to be invalid because 
they both represent sign-extension of the last implemented virtual address.

--
Khalid

WARNING: multiple messages have this Message-ID (diff)
From: Khalid Aziz <khalid.aziz@oracle.com>
To: Rob Gardner <rob.gardner@oracle.com>,
	davem@davemloft.net, corbet@lwn.net
Cc: viro@zeniv.linux.org.uk, nitin.m.gupta@oracle.com,
	mike.kravetz@oracle.com, akpm@linux-foundation.org,
	mingo@kernel.org, kirill.shutemov@linux.intel.com,
	adam.buchbinder@gmail.com, hughd@google.com, minchan@kernel.org,
	keescook@chromium.org, chris.hyser@oracle.com,
	atish.patra@oracle.com, cmetcalf@mellanox.com,
	atomlin@redhat.com, jslaby@suse.cz, joe@perches.com,
	paul.gortmaker@windriver.com, mhocko@suse.com,
	lstoakes@gmail.com, jack@suse.cz, dave.hansen@linux.intel.com,
	vbabka@suse.cz, dan.j.williams@intel.com, iamjoonsoo.kim@lge.com,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	sparclinux@vger.kernel.org, linux-mm@kvack.org,
	Khalid Aziz <khalid@gonehiking.org>
Subject: Re: [PATCH v5 4/4] sparc64: Add support for ADI (Application Data Integrity)
Date: Wed, 25 Jan 2017 22:57:36 +0000	[thread overview]
Message-ID: <97f5ad25-432c-f536-d2af-681288b7cca1@oracle.com> (raw)
In-Reply-To: <19f33a99-e719-a2a5-4330-390ed7755315@oracle.com>

On 01/25/2017 03:50 PM, Rob Gardner wrote:
> On 01/25/2017 03:20 PM, Khalid Aziz wrote:
>> On 01/25/2017 03:00 PM, Rob Gardner wrote:
>>> On 01/25/2017 12:57 PM, Khalid Aziz wrote:
>>>>
>>>> @@ -157,6 +158,24 @@ int __get_user_pages_fast(unsigned long start,
>>>> int nr_pages, int write,
>>>>       pgd_t *pgdp;
>>>>       int nr = 0;
>>>>   +#ifdef CONFIG_SPARC64
>>>> +    if (adi_capable()) {
>>>> +        long addr = start;
>>>> +
>>>> +        /* If userspace has passed a versioned address, kernel
>>>> +         * will not find it in the VMAs since it does not store
>>>> +         * the version tags in the list of VMAs. Storing version
>>>> +         * tags in list of VMAs is impractical since they can be
>>>> +         * changed any time from userspace without dropping into
>>>> +         * kernel. Any address search in VMAs will be done with
>>>> +         * non-versioned addresses. Ensure the ADI version bits
>>>> +         * are dropped here by sign extending the last bit before
>>>> +         * ADI bits. IOMMU does not implement version tags.
>>>> +         */
>>>> +        addr = (addr << (long)adi_nbits()) >> (long)adi_nbits();
>>>
>>>
>>> So you are depending on the sign extension to clear the ADI bits... but
>>> this only happens if there is a zero in that "last bit before ADI bits".
>>> If the last bit is a 1, then the ADI bits will be set instead of
>>> cleared.  That seems like an unintended consequence given the comment. I
>>> am aware of the value of adi_nbits() and of the number of valid bits in
>>> a virtual address on the M7 processor, but wouldn't using 'unsigned
>>> long' for everything here guarantee the ADI bits get cleared regardless
>>> of the state of the last non-adi bit?
>>
>> Sign extension is the right thing to do. MMU considers values of 0 and
>> 15 for bits 63-60 to be untagged addresses and expects bit 59 to be
>> sign-extended for untagged virtual addresses. The code I added is
>> explicitly meant to sign-extend, not zero out the top 4 bits.
>
> OK, that wasn't perfectly clear from the comment, which said "version
> bits are dropped".
>
> So sign extending will produce an address that the MMU can use, but will
> it produce an address that will allow a successful search in the page
> tables? ie, was this same sign extending done when first handing out
> that virtual address to the user?
>

Yes to both your questions. When virtual addresses are handed out, the 
last implemented virtual address bit is sign-extended. Sign-extending 
when dropping version bits preserves that original sign-extension. This 
is why MMU considers tag values of 0 as well as 15 to be invalid because 
they both represent sign-extension of the last implemented virtual address.

--
Khalid


WARNING: multiple messages have this Message-ID (diff)
From: Khalid Aziz <khalid.aziz@oracle.com>
To: Rob Gardner <rob.gardner@oracle.com>,
	davem@davemloft.net, corbet@lwn.net
Cc: viro@zeniv.linux.org.uk, nitin.m.gupta@oracle.com,
	mike.kravetz@oracle.com, akpm@linux-foundation.org,
	mingo@kernel.org, kirill.shutemov@linux.intel.com,
	adam.buchbinder@gmail.com, hughd@google.com, minchan@kernel.org,
	keescook@chromium.org, chris.hyser@oracle.com,
	atish.patra@oracle.com, cmetcalf@mellanox.com,
	atomlin@redhat.com, jslaby@suse.cz, joe@perches.com,
	paul.gortmaker@windriver.com, mhocko@suse.com,
	lstoakes@gmail.com, jack@suse.cz, dave.hansen@linux.intel.com,
	vbabka@suse.cz, dan.j.williams@intel.com, iamjoonsoo.kim@lge.com,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	sparclinux@vger.kernel.org, linux-mm@kvack.org,
	Khalid Aziz <khalid@gonehiking.org>
Subject: Re: [PATCH v5 4/4] sparc64: Add support for ADI (Application Data Integrity)
Date: Wed, 25 Jan 2017 15:57:36 -0700	[thread overview]
Message-ID: <97f5ad25-432c-f536-d2af-681288b7cca1@oracle.com> (raw)
In-Reply-To: <19f33a99-e719-a2a5-4330-390ed7755315@oracle.com>

On 01/25/2017 03:50 PM, Rob Gardner wrote:
> On 01/25/2017 03:20 PM, Khalid Aziz wrote:
>> On 01/25/2017 03:00 PM, Rob Gardner wrote:
>>> On 01/25/2017 12:57 PM, Khalid Aziz wrote:
>>>>
>>>> @@ -157,6 +158,24 @@ int __get_user_pages_fast(unsigned long start,
>>>> int nr_pages, int write,
>>>>       pgd_t *pgdp;
>>>>       int nr = 0;
>>>>   +#ifdef CONFIG_SPARC64
>>>> +    if (adi_capable()) {
>>>> +        long addr = start;
>>>> +
>>>> +        /* If userspace has passed a versioned address, kernel
>>>> +         * will not find it in the VMAs since it does not store
>>>> +         * the version tags in the list of VMAs. Storing version
>>>> +         * tags in list of VMAs is impractical since they can be
>>>> +         * changed any time from userspace without dropping into
>>>> +         * kernel. Any address search in VMAs will be done with
>>>> +         * non-versioned addresses. Ensure the ADI version bits
>>>> +         * are dropped here by sign extending the last bit before
>>>> +         * ADI bits. IOMMU does not implement version tags.
>>>> +         */
>>>> +        addr = (addr << (long)adi_nbits()) >> (long)adi_nbits();
>>>
>>>
>>> So you are depending on the sign extension to clear the ADI bits... but
>>> this only happens if there is a zero in that "last bit before ADI bits".
>>> If the last bit is a 1, then the ADI bits will be set instead of
>>> cleared.  That seems like an unintended consequence given the comment. I
>>> am aware of the value of adi_nbits() and of the number of valid bits in
>>> a virtual address on the M7 processor, but wouldn't using 'unsigned
>>> long' for everything here guarantee the ADI bits get cleared regardless
>>> of the state of the last non-adi bit?
>>
>> Sign extension is the right thing to do. MMU considers values of 0 and
>> 15 for bits 63-60 to be untagged addresses and expects bit 59 to be
>> sign-extended for untagged virtual addresses. The code I added is
>> explicitly meant to sign-extend, not zero out the top 4 bits.
>
> OK, that wasn't perfectly clear from the comment, which said "version
> bits are dropped".
>
> So sign extending will produce an address that the MMU can use, but will
> it produce an address that will allow a successful search in the page
> tables? ie, was this same sign extending done when first handing out
> that virtual address to the user?
>

Yes to both your questions. When virtual addresses are handed out, the 
last implemented virtual address bit is sign-extended. Sign-extending 
when dropping version bits preserves that original sign-extension. This 
is why MMU considers tag values of 0 as well as 15 to be invalid because 
they both represent sign-extension of the last implemented virtual address.

--
Khalid

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2017-01-25 22:58 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-25 19:57 [PATCH v5 0/4] Application Data Integrity feature introduced by SPARC M7 Khalid Aziz
2017-01-25 19:57 ` Khalid Aziz
2017-01-25 19:57 ` Khalid Aziz
2017-01-25 19:57 ` Khalid Aziz
2017-01-25 19:57 ` [PATCH v5 1/4] signals, sparc: Add signal codes for ADI violations Khalid Aziz
2017-01-25 19:57   ` Khalid Aziz
2017-01-25 19:57 ` [PATCH v5 2/4] mm: Add functions to support extra actions on swap in/out Khalid Aziz
2017-01-25 19:57   ` Khalid Aziz
2017-01-25 19:57   ` Khalid Aziz
2017-01-25 19:57 ` [PATCH v5 3/4] sparc64: Add support for ADI register fields, ASIs and traps Khalid Aziz
2017-01-25 19:57   ` Khalid Aziz
2017-01-25 19:57 ` [PATCH v5 4/4] sparc64: Add support for ADI (Application Data Integrity) Khalid Aziz
2017-01-25 19:57   ` Khalid Aziz
2017-01-25 19:57   ` Khalid Aziz
2017-01-25 22:00   ` Rob Gardner
2017-01-25 22:00     ` Rob Gardner
2017-01-25 22:00     ` Rob Gardner
2017-01-25 22:13     ` David Miller
2017-01-25 22:13       ` David Miller
2017-01-25 22:13       ` David Miller
2017-01-25 22:20     ` Khalid Aziz
2017-01-25 22:20       ` Khalid Aziz
2017-01-25 22:20       ` Khalid Aziz
2017-01-25 22:50       ` Rob Gardner
2017-01-25 22:50         ` Rob Gardner
2017-01-25 22:50         ` Rob Gardner
2017-01-25 22:57         ` Khalid Aziz [this message]
2017-01-25 22:57           ` Khalid Aziz
2017-01-25 22:57           ` Khalid Aziz
2017-01-30 22:15   ` David Miller
2017-01-30 22:15     ` David Miller
2017-01-30 22:15     ` David Miller
2017-01-31 23:38     ` Khalid Aziz
2017-01-31 23:38       ` Khalid Aziz
2017-01-31 23:38       ` Khalid Aziz
2017-02-01 17:18       ` David Miller
2017-02-01 17:18         ` David Miller
2017-02-01 17:18         ` David Miller

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=97f5ad25-432c-f536-d2af-681288b7cca1@oracle.com \
    --to=khalid.aziz@oracle.com \
    --cc=adam.buchbinder@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=atish.patra@oracle.com \
    --cc=atomlin@redhat.com \
    --cc=chris.hyser@oracle.com \
    --cc=cmetcalf@mellanox.com \
    --cc=corbet@lwn.net \
    --cc=dan.j.williams@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=hughd@google.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=jack@suse.cz \
    --cc=joe@perches.com \
    --cc=jslaby@suse.cz \
    --cc=keescook@chromium.org \
    --cc=khalid@gonehiking.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lstoakes@gmail.com \
    --cc=mhocko@suse.com \
    --cc=mike.kravetz@oracle.com \
    --cc=minchan@kernel.org \
    --cc=mingo@kernel.org \
    --cc=nitin.m.gupta@oracle.com \
    --cc=paul.gortmaker@windriver.com \
    --cc=rob.gardner@oracle.com \
    --cc=sparclinux@vger.kernel.org \
    --cc=vbabka@suse.cz \
    --cc=viro@zeniv.linux.org.uk \
    /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.