linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dan Williams <dan.j.williams@intel.com>
To: Tony Luck <tony.luck@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Andy Lutomirski <luto@amacapital.net>,
	linux-nvdimm <linux-nvdimm@ml01.01.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Robert <elliott@hpe.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	X86 ML <x86@kernel.org>
Subject: Re: [PATCH v8 3/3] x86, mce: Add __mcsafe_copy()
Date: Mon, 1 Feb 2016 15:16:54 -0800	[thread overview]
Message-ID: <CAPcyv4g0U_ein6XoznfHE2YozVx9bSuL2-qSw_ZiGGThZ61x+A@mail.gmail.com> (raw)
In-Reply-To: <CA+8MBbKSZKWQF5c+=P_c=jVkf0Xpky7ZJ4Jmyjq_RmDuNZnObA@mail.gmail.com>

On Mon, Feb 1, 2016 at 3:10 PM, Tony Luck <tony.luck@gmail.com> wrote:
>> The most optimal way of alternatively calling two functions would be
>> something like this, IMO:
>>
>> alternative_call(memcpy, __mcsafe_copy, X86_FEATURE_MCRECOVERY,
>>                  ASM_OUTPUT2("=a" (mcsafe_ret.trapnr), "=d" (mcsafe_ret.remain)),
>>                  "D" (dst), "S" (src), "d" (len));
>>
>> I hope I've not messed up the calling convention but you want the inputs
>> in %rdi, %rsi, %rdx and the outputs in %rax, %rdx, respectively. Just
>> check the asm gcc generates and do not trust me :)
>>
>> The other thing you probably would need to do is create our own
>> __memcpy() which returns struct mcsafe_ret so that the signatures of
>> both functions match.
>>
>> Yeah, it is a bit of jumping through hoops but this way we do a CALL
>> <func_ptr> directly in asm, without any JMPs or NOPs padding the other
>> alternatives methods add.
>>
>> But if you don't care about a small JMP and that is not a hot path, you
>> could do the simpler:
>>
>>         if (static_cpu_has(X86_FEATURE_MCRECOVERY))
>>                 return __mcsafe_copy(...);
>>
>>         return memcpy();
>>
>> which adds a JMP or a 5-byte NOP depending on the X86_FEATURE_MCRECOVERY
>> setting.
>
> Dan,
>
> What do you want the API to look like at the point you make a call
> in the libnvdimm code?  Something like:
>
>         r = nvcopy(dst, src, len);
>
> where the innards of nvcopy() does the check for X86_FEATURE_MCE_RECOVERY?
>
> What is useful to you in the return value? The low level __mcsafe_copy() returns
> both a remainder and a trap number. But in your case I don't think you
> need the trap
> number (if the remaining count is not zero, then there must have been a #MC. #PF
> isn't an option for you, right?

RIght, we don't need a trap number just an error.  This is the v1
attempt at integrating mcsafe_copy:

https://lists.01.org/pipermail/linux-nvdimm/2016-January/003869.html

I think the only change needed is to use
static_cpu_has(X86_FEATURE_MCRECOVERY) like so:

+static inline int arch_memcpy_from_pmem(void *dst, const void __pmem *src,
+ size_t n)
+{
+ if (static_cpu_has(X86_FEATURE_MCRECOVERY)) {
+ struct mcsafe_ret ret;
+
+ ret = __mcsafe_copy(dst, (void __force *) src, n);
+ if (ret.remain)
+ return -EIO;
+ return 0;
+ }
+ memcpy(dst, (void __force *) src, n);
+ return 0;
+}

--
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:[~2016-02-01 23:16 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-09  0:04 [PATCH v8 0/3] Machine check recovery when kernel accesses poison Tony Luck
2015-12-31 19:40 ` [PATCH v8 2/3] x86, mce: Check for faults tagged in EXTABLE_CLASS_FAULT exception table entries Tony Luck
2016-01-08 20:49 ` [PATCH v8 1/3] x86: Expand exception table to allow new handling options Tony Luck
2016-01-09  1:52   ` Andy Lutomirski
2016-01-09  3:39     ` Brian Gerst
2016-01-09  4:31       ` Brian Gerst
2016-01-09  6:36         ` Andy Lutomirski
2016-01-11 23:09           ` Brian Gerst
2016-01-11 23:22             ` Andy Lutomirski
2016-01-11 23:48             ` Luck, Tony
2016-01-09 17:45     ` Tony Luck
2016-01-09 18:00       ` Andy Lutomirski
2016-01-09 19:51         ` Tony Luck
2016-01-09 22:32           ` Andy Lutomirski
2016-01-10  1:15             ` Tony Luck
2016-01-11  0:25     ` Luck, Tony
2016-01-08 21:18 ` [PATCH v8 3/3] x86, mce: Add __mcsafe_copy() Tony Luck
2016-01-09  1:49   ` Andy Lutomirski
2016-01-09 17:48     ` Tony Luck
2016-01-09 17:57       ` Andy Lutomirski
2016-01-09 19:39         ` Tony Luck
2016-01-09 22:15           ` Dan Williams
2016-01-09 22:33             ` Andy Lutomirski
2016-01-10  0:23               ` Dan Williams
2016-01-10  1:40                 ` Tony Luck
2016-01-10 11:26                   ` Borislav Petkov
2016-01-11 10:44                     ` Ingo Molnar
2016-01-13 23:22                       ` Tony Luck
2016-01-14  4:39                         ` Borislav Petkov
2016-01-30  0:35                           ` Tony Luck
2016-01-30 10:28                             ` Borislav Petkov
2016-02-01 23:10                               ` Tony Luck
2016-02-01 23:16                                 ` Dan Williams [this message]
2016-01-12  0:26     ` Luck, Tony
2016-01-12  0:30       ` Andy Lutomirski
2016-01-12  0:37       ` Andy Lutomirski

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=CAPcyv4g0U_ein6XoznfHE2YozVx9bSuL2-qSw_ZiGGThZ61x+A@mail.gmail.com \
    --to=dan.j.williams@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=bp@alien8.de \
    --cc=elliott@hpe.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-nvdimm@ml01.01.org \
    --cc=luto@amacapital.net \
    --cc=mingo@kernel.org \
    --cc=tony.luck@gmail.com \
    --cc=x86@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox