Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2033715ybz; Sat, 18 Apr 2020 13:54:06 -0700 (PDT) X-Google-Smtp-Source: APiQypJ7Gs/QN6lQwGGb80Ca+e4RuuN47bm0jIoRK2ni4AJU9+JgcaTFgkHLmDG7Pn/7kc/gAZwN X-Received: by 2002:a17:906:1e47:: with SMTP id i7mr9235837ejj.286.1587243246088; Sat, 18 Apr 2020 13:54:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587243246; cv=none; d=google.com; s=arc-20160816; b=kOdNAVjVYAHAc7LQHa2P94L22SMU0ho4Uo0g8HkDpC1NECXUEOHT/tE9M3vbiNt949 44FAL/ieDbUZp/AS+oKPQX28LHPLZXpt0N2DZfVx7H9GHWdhoMOBUSsWaThsR0JFhhQ4 Ix6q9RA36FlVc0uyQauppE4LXTcxwpZAZHx+OEpuOXK6x+OKrpiu32VNFh7NQq/IdNjh fmPlTdnZEpkdP788T7fmtStR0ynIQnptx+BRPa20SKcVRk9rqfA3CrXafk/i3lGEZahd /qlgP0UZ32G1Yz81QM5Wa3VayTq5Rqr3k2wgikzDwx9vEP4zjviONvwv46cGRGpzKSYy XSKg== 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:in-reply-to:references:mime-version :dkim-signature; bh=s/MCXYluiV/Di6rRKjHU/d4NnQSkJUzqjX8QxIsHmUc=; b=SKAkSFV7ENuxpq3AmZDckY8T39Zkz4N5C3mc2EE41DfQYXtWPaaMSxommPzKITtB0N MepYLc3Jt9Frc/8P3VPzxaJuHkV8kr++ZmGza34MMRmpzaXDSMgMwNv6ZoTESPWNq+C5 jqdnzXyWNFPx2c/wHK8MN0JjswL9KltSHoroEEIEWA8Nv4jsjTShBK0vKnQn/ztRGCSP 2ct86geQzo/hWswq1Qg16iPAkFgPXBmh5EACzki1L0poil6BlVzad2tCiBv/QEfMyEtf tND6yxpPBEPNFhIh++EoiGAljs6kznDTza/K/CSSZQy3T5WWZRw6hnFkfIWJyuEP3WG/ mZvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Ieynsinq; 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 j3si16836997ejb.482.2020.04.18.13.53.38; Sat, 18 Apr 2020 13:54:06 -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=Ieynsinq; 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 S1727992AbgDRUwg (ORCPT + 99 others); Sat, 18 Apr 2020 16:52:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726014AbgDRUwg (ORCPT ); Sat, 18 Apr 2020 16:52:36 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9872C061A0F for ; Sat, 18 Apr 2020 13:52:34 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id m2so4726413lfo.6 for ; Sat, 18 Apr 2020 13:52:34 -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:content-transfer-encoding; bh=s/MCXYluiV/Di6rRKjHU/d4NnQSkJUzqjX8QxIsHmUc=; b=IeynsinqAESZ7D5iH0Mw7AG00cif0HeQeEDlNnZHliL9sMslW01AUBwTualDAKcx6x vICf3ReOAIMcS25qObUhbwk3qGc/BhprOp/3VHZEytcvQY4Pv2D4bBv88lxtaCvewGqg DnGnok45WuhxHNH5EwyksqWHkDHRbvN//rwvQ= 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:content-transfer-encoding; bh=s/MCXYluiV/Di6rRKjHU/d4NnQSkJUzqjX8QxIsHmUc=; b=X1dcQJhZr20g18p781T0toQHxmtdlOJfFdjsn/k6C1FcmzeDRJ+wQCgpuF/XBoYuwB /ruG8sJDsIlEAxQtYf+DmUKY6DwMKoRCBdDuQ8ZR6G5MgYqD2n3KkFIajfue/Q/WAO/v SN9OKUvA2kte+pNgW+rMjc5Na3KByuWdzJpwLFZk0tL+pGZKTCe9TGWgE0MhbV3FewY9 wyWOfsoQxO4fqpo01Z2T7ul3lI4LGVWMavpMQOWlGtJsSGOUTcS+sWg5QVa/ML+Ao7VV jPr4qdFp16Brw/wWom8kErOp6oz2kj3AmSV2BTBowi1hIcdcn9BcamW64m1sl2BfcS7l iybQ== X-Gm-Message-State: AGi0PuYIa+eUFSRONeGQolnIZrMnL8QSNYgF4qyZlx+Hjo0xRZu9CfMV x/hyzs24KMHddloRfGXCQzGBbPvDVIQ= X-Received: by 2002:ac2:4551:: with SMTP id j17mr5770370lfm.147.1587243152674; Sat, 18 Apr 2020 13:52:32 -0700 (PDT) Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com. [209.85.167.43]) by smtp.gmail.com with ESMTPSA id 64sm19322217ljj.41.2020.04.18.13.52.31 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 18 Apr 2020 13:52:31 -0700 (PDT) Received: by mail-lf1-f43.google.com with SMTP id m2so4726356lfo.6 for ; Sat, 18 Apr 2020 13:52:31 -0700 (PDT) X-Received: by 2002:ac2:4466:: with SMTP id y6mr5848677lfl.125.1587243150793; Sat, 18 Apr 2020 13:52:30 -0700 (PDT) MIME-Version: 1.0 References: <67FF611B-D10E-4BAF-92EE-684C83C9107E@amacapital.net> In-Reply-To: <67FF611B-D10E-4BAF-92EE-684C83C9107E@amacapital.net> From: Linus Torvalds Date: Sat, 18 Apr 2020 13:52:15 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] x86/memcpy: Introduce memcpy_mcsafe_fast To: Andy Lutomirski Cc: Dan Williams , Thomas Gleixner , Ingo Molnar , X86 ML , stable , Borislav Petkov , "H. Peter Anvin" , Peter Zijlstra , Tony Luck , Erwin Tsaur , Linux Kernel Mailing List , linux-nvdimm 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 Sat, Apr 18, 2020 at 1:30 PM Andy Lutomirski wrote= : > > Maybe I=E2=80=99m missing something obvious, but what=E2=80=99s the alter= native? The _mcsafe variants don=E2=80=99t just avoid the REP mess =E2=80= =94 they also tell the kernel that this particular access is recoverable vi= a extable. .. which they could easily do exactly the same way the user space accessors do, just with a much simplified model that doesn't even care about multiple sizes, since unaligned accesses weren't valid anyway. The thing is, all of the MCS code has been nasty. There's no reason for it what-so-ever that I can tell. The hardware has been so incredibly broken that it's basically unusable, and most of the software around it seems to have been about testing. So I absolutely abhor that thing. Everything about that code has screamed "yeah, we completely mis-designed the hardware, we're pushing the problems into software, and nobody even uses it or can test it so there's like 5 people who care". And I'm pushing back on it, because I think that the least the code can do is to at least be simple. For example, none of those optimizations should exist. That function shouldn't have been inline to begin with. And if it really really matters from a performance angle that it was inline (which I doubt), it shouldn't have looked like a memory copy, it should have looked like "get_user()" (except without all the complications of actually having to test addresses or worry about different sizes). And it almost certainly shouldn't have been done in low-level asm either. It could have been a single "read aligned word" interface using an inline asm, and then everything else could have been done as C code around it. But no. The software side is almost as messy as the hardware side is. I hate it. And since nobody sane can test it, and the broken hardware is _so_ broken than nobody should ever use it, I have continually pushed back against this kind of ugly nasty special code. We know the writes can't fault, since they are buffered. So they aren't special at all. We know the acceptable reads for the broken hardware basically boil down to a single simple word-size aligned read, so you need _one_ special inline asm for that. The rest of the cases can be handled by masking and shifting if you really really need to - and done better that way than with byte accesses anyway. Then you have _one_ C file that implements everything using that single operation (ok, if people absolutely want to do sizes, I guess they can if they can just hide it in that one file), and you have one header file that exposes the interfaces to it, and you're done. And you strive hard as hell to not impact anything else, because you know that the hardware is unacceptable until all those special rules go away. Which they apparently finally have. Linus