Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2218839ybz; Thu, 30 Apr 2020 13:02:50 -0700 (PDT) X-Google-Smtp-Source: APiQypKuEKg8VYpvK6JD+8UU2eINxAtJNVGXEnU/5rt4txCewLJlnYFXrbj54Iz3jSshlKR1Jq6b X-Received: by 2002:a17:907:435d:: with SMTP id oc21mr128245ejb.100.1588276970754; Thu, 30 Apr 2020 13:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588276970; cv=none; d=google.com; s=arc-20160816; b=IIBsKknU/SLiAL215RSa/+1Z2Z/CpgQ3Gz8IrV0oDpJXUzZ5cgEqw8ujEZ0PywCKTR uk6mHBsf0giUKUsHt3FVAZjzYwjrcgc0wYzIlwtqZUoDx9oKWwLX+zNl17dUqmkR5B4y jxY3yscziuZISPBOD0tIz/7Kjzm2XLtuNmjV+d4NAnXfaKTUTEXjKDRPMhboggAbSyKg c4l+Jjfvh1kTRUnTrGOIGN9bz5fiQ9v5E/G5z+5dRLAt8SWy6cDl3EFRRZhCSNmgX+Hg tWzwRE2wrImBRpJ1sIJBF8emWeVNztRcMcWyQN5f8x1nPQxXzT/wtSq0NxiK2KTQGeEW awkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=buJprfejQSl5yOput5ZzEt1+jJW0SdBoSZ4YNZtieEY=; b=x04VrXdcxkEp35OGqutyg4LVzjtdfnCFzp3aY92qdTI0Ts/4zIrHIMoLVBuGzxp02y KdJ6e8e3xlaQLQpqg23aTeOM9Ay7FIB1Lgc/9Ma8KI4AFzuFd1PJWeLgkcRKIlv+3k4j VVnpciZ9YcSzbwIjey/G5tCyuefktSdy26/9S6vfkBJ/a46cpBl1PLgHrXagvjagB6w0 8xkGtynXrnOijp2J1TH7O+W1tsrJI5wHcom5+RjKU5huOOKP1rorh3MztkEvrV4S7zhj 2Irv4OYJIT6u8SKBAr8kAbFmXqcV+zcnjHW/M12ZPvfZ7yPXpzm3THLVuPI9SS6aN6rR nIzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="VUySWc9/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x25si418836ejs.434.2020.04.30.13.02.25; Thu, 30 Apr 2020 13:02:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="VUySWc9/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726790AbgD3T6p (ORCPT + 99 others); Thu, 30 Apr 2020 15:58:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726548AbgD3T6o (ORCPT ); Thu, 30 Apr 2020 15:58:44 -0400 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3E9FC035494 for ; Thu, 30 Apr 2020 12:58:42 -0700 (PDT) Received: by mail-ed1-x541.google.com with SMTP id d16so5566381edq.7 for ; Thu, 30 Apr 2020 12:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=buJprfejQSl5yOput5ZzEt1+jJW0SdBoSZ4YNZtieEY=; b=VUySWc9/2/N9fwGhjHudR0NYsyMdMYZXogyCdl4rAuef6cbEQbsUZSSi0oWuzE4z5h oCVQ61Pc7cnFxML60ozbbHuETGxsnqdWrMhn5WWKV0YPtGOtTP7g+li2MpWKMXtZQPIL fURRW8u5/c5rMyeSpaud7CEBjaUNeWdlVUYJY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=buJprfejQSl5yOput5ZzEt1+jJW0SdBoSZ4YNZtieEY=; b=afdf0n64CoL0LK4l3ALQ0XfP22DoajcKyVP2XcdyCDR/qjW0dtxTQ04zUfPpMvzb3m RVrKkz/G1O6YEx2+VLOVDCKjTuNoegUdnynl2s1sdsPlrW0+caBBKxLYAK0IVL6CyV0J fcPhVNBicE8j46UORWrE90hzmq6UWIj2MFkXs9FdRV19SP6rP7Gk4Zb79MSMJolHccr0 rEDu9ZavCXaxR7u80KHFAeoImguqyL2rzmU3ztB161J6DP7gR7k1e9IawkAVkq14AmYm RLwZmWaM7yYphFdDKywLCWO1GKXz8T8LtZM/fs3EW9AEcCwy2lLTc/m1KARWzsaQgJqn gFAA== X-Gm-Message-State: AGi0PuY7LhQ9Z6zmgtyLntGKFOhBIhfDb54aUpldxejY0iCWAi3khJ1I GRjEuRJ2H8LlIAsLVFxcBrgxZtcT0rw= X-Received: by 2002:aa7:cd06:: with SMTP id b6mr605283edw.67.1588276721219; Thu, 30 Apr 2020 12:58:41 -0700 (PDT) Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com. [209.85.208.53]) by smtp.gmail.com with ESMTPSA id co22sm51823edb.30.2020.04.30.12.58.40 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 30 Apr 2020 12:58:41 -0700 (PDT) Received: by mail-ed1-f53.google.com with SMTP id a8so5585447edv.2 for ; Thu, 30 Apr 2020 12:58:40 -0700 (PDT) X-Received: by 2002:a05:6512:1114:: with SMTP id l20mr178100lfg.31.1588276256935; Thu, 30 Apr 2020 12:50:56 -0700 (PDT) MIME-Version: 1.0 References: <158823509800.2094061.9683997333958344535.stgit@dwillia2-desk3.amr.corp.intel.com> <20200430192258.GA24749@agluck-desk2.amr.corp.intel.com> In-Reply-To: <20200430192258.GA24749@agluck-desk2.amr.corp.intel.com> From: Linus Torvalds Date: Thu, 30 Apr 2020 12:50:40 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 0/2] Replace and improve "mcsafe" with copy_safe() To: "Luck, Tony" Cc: Andy Lutomirski , Dan Williams , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Borislav Petkov , stable , "the arch/x86 maintainers" , "H. Peter Anvin" , Paul Mackerras , Benjamin Herrenschmidt , Erwin Tsaur , Michael Ellerman , Arnaldo Carvalho de Melo , linux-nvdimm , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 30, 2020 at 12:23 PM Luck, Tony wrote: > > 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). That just makes things worse. The problem isn't "what fault did I get?". The problem is "what is the point of this function?". In other words, I want the code to explain _why_ it uses a particular function. So the question the function should answer is not "Why did it take a fault?", but "Why isn't this just a 'memcpy()'"? When somebody writes x = copy_to_user(a,b,c); the "why is it not a memcpy" question never comes up, because the code is obvious. It's not a memory copy, because it's copying to user space, and user space is different! In contrast, if you write x = copy_safe(a,b,c); then what is going on? There is no rhyme or reason to the call. Is the source unsafe? Wny? Is the destination faulting? Why? Both? How? So "copy_to_user()" _answers_ a question. But "copy_safe()" just results in more questions. See the difference? And notice that the "why did it fault" question is NOT about your "what kind of fault did it take" question. That question is generally pretty much uninteresting. The question I want answered is "why is this function being called AT ALL". Again, "copy_to_user()" can fail, and we know to check failure cases. But more importantly, the _reason_ it can fail is obvious from the name and from the use. There's no confusion about "why". "copy_safe()"? or "try_copy_catch()"? No such thing. It doesn't answer that fundamental "why" question. And yes, this also has practical consequences. If you know that the failure is due to the source being some special memory (and if we care about the MC case with unaligned accesses), then the function in question should probably strive to make those _source_ accesses be the aligned ones. But if it's the destination that is special memory, then it's the writes to the destination that should be aligned. If you need both, you may need to be either mutually aligned, or do byte accesses, or do special shifting copies. So it matters for any initial alignment code (if the thing has alignment issues to begin with). I haven't even gotten an answer to the "why would the write fail". When I asked, Dan said "writes can mmu-fault now that memcpy_mcsafe() is also used by _copy_to_iter_mcsafe()" but as mentioned, the only reason I can find for _that_ is that the destination is user space. In which case a "copy_safe()" absolutely could never work. If I can't figure out the "why is this function used" or even figure out why it needs the semantics it claims it needs, then there's a problem. Personally, I suspect that the *easiest* way to support the broken nvdimm semantics is to not have a "copy" function at all as the basic accessor model. Why? Exactly because "copy" is not a fundamental well-defined action. You get nasty combinatorial explosions of different things, where you have three different kinds of sources (user, RAM, nvdimm) and three different kinds of destinations. And that's ignoring the whole "maybe you don't want to do a plain copy, maybe you want to calculate a RAID checksum, or do a 'strcpy()' or whatever". If those are ever issues, you get another explosion of combinations. The only *fundamental* access would likely be a single read/write operation, not a copy operation. Think "get_user()" instead of "copy_from_user()". Even there you get combinatorial explosions with access sizes, but you can often generate those automatically or with simple patterns, and then you can build up the copy functions from that if you really need to. Linus