[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <4819995F-4EAE-46EE-8311-9CF65CB8D08A@amacapital.net>
Date: Thu, 30 Apr 2020 13:07:09 -0700
From: Andy Lutomirski <luto@...capital.net>
To: Dan Williams <dan.j.williams@...el.com>
Cc: "Luck, Tony" <tony.luck@...el.com>,
Andy Lutomirski <luto@...nel.org>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Borislav Petkov <bp@...en8.de>,
stable <stable@...r.kernel.org>,
the arch/x86 maintainers <x86@...nel.org>,
"H. Peter Anvin" <hpa@...or.com>,
Paul Mackerras <paulus@...ba.org>,
Benjamin Herrenschmidt <benh@...nel.crashing.org>,
Erwin Tsaur <erwin.tsaur@...el.com>,
Michael Ellerman <mpe@...erman.id.au>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
linux-nvdimm <linux-nvdimm@...ts.01.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 0/2] Replace and improve "mcsafe" with copy_safe()
> On Apr 30, 2020, at 12:51 PM, Dan Williams <dan.j.williams@...el.com> wrote:
>
> On Thu, Apr 30, 2020 at 12:23 PM Luck, Tony <tony.luck@...el.com> wrote:
>>
>>> On Thu, Apr 30, 2020 at 11:42:20AM -0700, Andy Lutomirski wrote:
>>> I suppose there could be a consistent naming like this:
>>>
>>> copy_from_user()
>>> copy_to_user()
>>>
>>> copy_from_unchecked_kernel_address() [what probe_kernel_read() is]
>>> copy_to_unchecked_kernel_address() [what probe_kernel_write() is]
>>>
>>> copy_from_fallible() [from a kernel address that can fail to a kernel
>>> address that can't fail]
>>> copy_to_fallible() [the opposite, but hopefully identical to memcpy() on x86]
>>>
>>> copy_from_fallible_to_user()
>>> copy_from_user_to_fallible()
>>>
>>> These names are fairly verbose and could probably be improved.
>>
>> How about
>>
>> try_copy_catch(void *dst, void *src, size_t count, int *fault)
>>
>> returns number of bytes not-copied (like copy_to_user etc).
>>
>> if return is not zero, "fault" tells you what type of fault
>> cause the early stop (#PF, #MC).
>
> I do like try_copy_catch() for the case when neither of the buffers
> are __user (like in the pmem driver) and _copy_to_iter_fallible()
> (plus all the helpers it implies) for the other cases.
>
> copy_to_user_fallible
> copy_fallible_to_page
> copy_pipe_to_iter_fallible
>
> ...because the mmu-fault handling is an aspect of "_user" and fallible
> implies other source fault reasons. It does leave a gap if an
> architecture has a concept of a fallible write, but that seems like
> something that will be handled asynchronously and not subject to this
> interface.
I’m suspicious that, as a practical matter, x86 does have a fallible write. In particular, if a page fails and the memory failure code is notified, the page will be unmapped. At that point, an attempt to write to the failed fallible page will get #PF, and code that writes to it needs to be prepared to handle #PF. Perhaps copy_to_fallible(), etc can still return void, but I’m unconvinced
the implementation can be the same as memcpy.
Powered by blists - more mailing lists