Received: by 10.192.165.148 with SMTP id m20csp1908132imm; Thu, 3 May 2018 07:20:07 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrfmwWGsW+tnqHZkpiS01izq3nwkkdzN2mUaSAzs5r54Fz6l0HBof5wq5QDDVe2RATyCITf X-Received: by 2002:a17:902:7b86:: with SMTP id w6-v6mr2352760pll.183.1525357207274; Thu, 03 May 2018 07:20:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525357207; cv=none; d=google.com; s=arc-20160816; b=dOdSAPhnvTvwrP9LFUlEYk+WxhSmJ0rA0SxN1D2Tx47AcbXo2xmgtTiY2A8knS+xhS kLLYQMakhjRLzoslte2PRZUBl06i1N82rMgVSNPGst9aoUYCeMS2KPQjKK/EEB5J0bUo o6E6DA2ig7L4NxRiEouvvMqpIL6EmNTsuVQ1IANstNOHJSQOg6YsLtimmlsMEgqqqmV1 4ysFyBW6lSUEBlgdJ+Kj5wdSvi3alp1vExghB1qp9F2QAuY5PwLvewFbH0wp0UnYpoWp 4RPGPJMnYA2gyvNBadBxQnIozz/IwVRCgwLNKv5JjgDGONbkt2bvyY+2oQOBV/xzoIvZ mlbQ== 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:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=4e48Jp2ea/x1CyZ5MCBI3AKeRRF71qTSURGtnW2xnSM=; b=m3SksbzeranMh7MUutZH3OudxVcT+/lpGQ6JYbr6dRBWvseBP7ATtxgaB099a/Lwje O1OocvHzq5jZ85mIo1s9TKWZJk6rGQXzGfy5NoOMvgpt4FNcjUBxOfUc0ou67swID1gv SmOW0/TRnVaoT3bbf3/UKUSe2ryK33clIxIr9McVeA8FqE7N/hM7QYWpotwSM3/R5ZNe y1W4Hf2mXC02L6nwvg0ENCbOLt0Q6G/WnXj1xAwloTnYOVGf29BPawZhs1JxfP5yRSRv xICoREgX5/O7Z26ZveDshhnldgCMY2mfF1mVfvUvumiYXr8i9Wns6PJRRTi3VFpXHu/d pocQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=QbDa1+Jv; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z18-v6si11346455pgc.99.2018.05.03.07.19.52; Thu, 03 May 2018 07:20:07 -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=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=QbDa1+Jv; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751499AbeECOTg (ORCPT + 99 others); Thu, 3 May 2018 10:19:36 -0400 Received: from mail-oi0-f51.google.com ([209.85.218.51]:34713 "EHLO mail-oi0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751234AbeECOTY (ORCPT ); Thu, 3 May 2018 10:19:24 -0400 Received: by mail-oi0-f51.google.com with SMTP id l1-v6so16206260oii.1 for ; Thu, 03 May 2018 07:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=4e48Jp2ea/x1CyZ5MCBI3AKeRRF71qTSURGtnW2xnSM=; b=QbDa1+JvK9rnwHbn0IgYjT7iAeALAXmrDlnhlPgKWbH2kf541z19wjzQjZhcEr9KEW rVJDNHMQYL1utei7hRtck4N+I583kpoOH4bBtSna99RRH3gJEBB0ZVWyVf0rqIOI5qqN 63HlfAQc3RwOP20/mzAD4jWO+PlMJcW9D00TVB0pWhtTbgsjNxhT9eLoPIw+k+pP5XlS +9gmB+ZZwQpF11uTadeN47IDG+AgtZmDCdYIQBLyGYZcXrKFQEjORboHI+PzWh08/u4q FWubYUMln6kUTslUgM7tx/NYt+oyJXhF0WtVdS40Nx7hrMjfd+Y5C/yq5WuG4ir/bNrr zNnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=4e48Jp2ea/x1CyZ5MCBI3AKeRRF71qTSURGtnW2xnSM=; b=ozLPJIDIkAeSGSTK9COqFosXT0v1N2gb124vdv/1y9snXZ7iir+aKv+i+8aFttt6VT wrvNRNh903cSNapQQwdcHrWnkeddxltDG/2rs7mRHZM8irqzO3/u737brziH5prOug/n UfIM/Ro7wUmXmjUEpd/OBm4E7e79ZJR9WFL9wFQhC2pFsKPdSh7TIomtuC6uTC6c9ayN 57gSgneJuuoSQ1VPjEwZptMBMJkhI5CQgZIuJdq87iGWmJYdx8+/U9SuzrFXk8ce+Pye 4+JWBO4NCuBbRpUJG54pRp//gaD4U1YYCgSPiTXxM1y1raiGuaS2RpwkwsaFgv1Umk7e ug3A== X-Gm-Message-State: ALQs6tAu9kuvkc0uCVWz+bGI1cxbvU5W6tgSYmku9yQFkaaOBnAa9IDP 9uzjoa/DMEAvF/IibRC8C+JoihDp65IE/v9gBbALsg== X-Received: by 2002:aca:ebd4:: with SMTP id j203-v6mr15764610oih.110.1525357164412; Thu, 03 May 2018 07:19:24 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:2d36:0:0:0:0:0 with HTTP; Thu, 3 May 2018 07:19:23 -0700 (PDT) In-Reply-To: <69d19601-df56-687d-730e-d043b2cf7161@nextfour.com> References: <152532351517.17218.3583455156840230837.stgit@dwillia2-desk3.amr.corp.intel.com> <152532354268.17218.11923624861859552990.stgit@dwillia2-desk3.amr.corp.intel.com> <69d19601-df56-687d-730e-d043b2cf7161@nextfour.com> From: Dan Williams Date: Thu, 3 May 2018 07:19:23 -0700 Message-ID: Subject: Re: [PATCH v2 4/9] x86, memcpy_mcsafe: add write-protection-fault handling To: =?UTF-8?Q?Mika_Penttil=C3=A4?= Cc: linux-nvdimm , X86 ML , Ingo Molnar , Borislav Petkov , Tony Luck , Al Viro , Thomas Gleixner , Andy Lutomirski , Peter Zijlstra , Andrew Morton , Linus Torvalds , Christoph Hellwig , Linux Kernel Mailing List , linux-fsdevel Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 2, 2018 at 10:29 PM, Mika Penttil=C3=A4 wrote: > On 05/03/2018 07:59 AM, Dan Williams wrote: >> In preparation for using memcpy_mcsafe() to handle user copies it needs >> to be to handle write-protection faults while writing user pages. Add >> MMU-fault handlers alongside the machine-check exception handlers. >> >> Note that the machine check fault exception handling makes assumptions >> about source buffer alignment and poison alignment. In the write fault >> case, given the destination buffer is arbitrarily aligned, it needs a >> separate / additional fault handling approach. The mcsafe_handle_tail() >> helper is reused. The @limit argument is set to @len since there is no >> safety concern about retriggering an MMU fault, and this simplifies the >> assembly. >> > >> diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c >> index 75d3776123cc..9787f5ee0cf9 100644 >> --- a/arch/x86/lib/usercopy_64.c >> +++ b/arch/x86/lib/usercopy_64.c >> @@ -75,6 +75,23 @@ copy_user_handle_tail(char *to, char *from, unsigned = len) >> return len; >> } >> >> +/* >> + * Similar to copy_user_handle_tail, probe for the write fault point, >> + * but reuse __memcpy_mcsafe in case a new read error is encountered. >> + * clac() is handled in _copy_to_iter_mcsafe(). >> + */ >> +__visible unsigned long >> +mcsafe_handle_tail(char *to, char *from, unsigned len) >> +{ >> + for (; len; --len, to++) { >> + unsigned long rem =3D memcpy_mcsafe(to, from, 1); >> + > > > Hmm why not > for (; len; --len, from++, to++) > > Why not indeed. Great catch, I'll fix this and extend the unit test to verify the data transfer as well.