Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp779858ybg; Fri, 12 Jun 2020 14:38:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGbMKoIDohwgL79EaDjo1Zzk+iutXjaAmBtIW2KxWKBAVBOKOlATWqF3uzx53xEQaRIhWI X-Received: by 2002:a50:f297:: with SMTP id f23mr13389164edm.222.1591997899139; Fri, 12 Jun 2020 14:38:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591997899; cv=none; d=google.com; s=arc-20160816; b=vH0r3ZcQf1kDjWpw3gD+qB2ZvYR4Ml+J+2UeBXqY4iC8eHGk4oWcsNKW7ec94YWETC j0gLMuPQYCUyuO3+cvj2xeoX67r0oYBEVlNTmLL5VMjmFKgQszG6nQKUZh5d9DQVolKm lTH29oDANCsfEXC0+YrDQdlj9bmPBI0dEMZ8IHWHEP2+1wEAU6HSMnWxskggdl/04z04 dSdWztnFJqkNXm6LXbbOXLZ1I6vApOS3NyRMre27eLiW0tna13c0o+NoSOYVDywofKUY hmCEyeqxeiNIuU4pAWa+WXN/aMnUkhbD/pk7BATX1NmGG5lq7hY06l6GBJo6teOYnzOk /ncA== 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=0GLuAsGyzw8XHhb9/Fo63Z5vxlJgDAQ39CGDhGwS054=; b=K0lfjIgz1WdFoUOrdRwO48/4tGK4y3aesEOS7LeXEAWrVcKmF2q6xvoiW9sp1+RRHv 0OFEW5JDtXLjK3JsG8CwX6aAWgPgG67koGjhQcbqKUGz9nwdtbNQ9eYGQtiARiLIogz5 eyGAM2JOTo/wCb1CchgoQdylZcf4TdthgSd2wC7nRsaxeRokGRrKU0l+VKYyId8V1Wp9 /3oeqGgGPQ06mZJa4yU+bRP0EJIUadJ5KSx341HtQosV8LKGdSo8lmDOM2h7LTNJL2EH 5xE6j9s8SZxoWybD38kDx8MHB7wSNrjdTRePfp3ZPmvRWDN/kgQCKHZjqgwL1rAV4ZhB 6WMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=rbkQ2oj9; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c6si4437426edw.220.2020.06.12.14.37.56; Fri, 12 Jun 2020 14:38:19 -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=@google.com header.s=20161025 header.b=rbkQ2oj9; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726338AbgFLVdW (ORCPT + 99 others); Fri, 12 Jun 2020 17:33:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726314AbgFLVdV (ORCPT ); Fri, 12 Jun 2020 17:33:21 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AB96C03E96F for ; Fri, 12 Jun 2020 14:33:21 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id j1so4911311pfe.4 for ; Fri, 12 Jun 2020 14:33:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=0GLuAsGyzw8XHhb9/Fo63Z5vxlJgDAQ39CGDhGwS054=; b=rbkQ2oj9O9gTPPbPoOCPZmUZbaMeD2elX037NDfoqa9tP8JAUYHbOz8B0Yij58YAnq 8/qRFpWyBd0PuSOTxponSdBG0KZaj2LBuyk5Bs76l1F9UkvD++szIxYDDkAMNtFLhTgV cDNNOn2iz++xIG0WRGJfn0L/qhvejS92Z9BQxCeFacxt/Rgl2D3mzj3t3bjJx3fgerVx NzjDa+EQtwOHivdCuc3kXny+vCBboe/x9e0jf289ztzXvxrR3zQza+sUiRNIhQ2oxk/I HADTlxXkiDpDHipgeR3She05KK63aDyBYO5N6Y6EBmwpuMrGi+MctEpYDstcw33IJ2pW Iegw== 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=0GLuAsGyzw8XHhb9/Fo63Z5vxlJgDAQ39CGDhGwS054=; b=SVTVjE6DWu4971PV705MfmJ2c/dH4Jo8oQiKj22ZKAKo+7X+B+l4/rl0t0GoCOzbks 1ZoDS7/GQLemPOBRYFh0K4+3tRamhUYB4lLS5bQ/UXO9q/HxhhM7cKEqwh+c6mrjp57m fc7tE5fBex60HbbfpMrPgbSqhPDvOWppjpkCSDlLAquDZtH89kr31gLdJx4i747z6DHN iew8LjGXKut2LEuHLFXG4yabirKu/Zp0myh3JnO6ktUDGws4GTEcYvPaQYWM35y7DhoF HUTGv621kHj98JRSmaj8BZB3edbtgCyndbR5v4mfUceywFcx1zu92qLHYQlQZqJbLeN3 bBYA== X-Gm-Message-State: AOAM532KY6yKdkFAIw9URv64R03tODyoeolG38jF9dtzZRQBFqrlTKro GyOUGI+sNa8KvxhyOEi6ys9etMZFiUX1HnzbW8C5Uo9c6gw= X-Received: by 2002:a63:f00d:: with SMTP id k13mr12942397pgh.263.1591997600747; Fri, 12 Jun 2020 14:33:20 -0700 (PDT) MIME-Version: 1.0 References: <49YBKY13Szz9sT4@ozlabs.org> <20200611224355.71174-1-ndesaulniers@google.com> <20200611235256.GL31009@gate.crashing.org> In-Reply-To: <20200611235256.GL31009@gate.crashing.org> From: Nick Desaulniers Date: Fri, 12 Jun 2020 14:33:09 -0700 Message-ID: Subject: Re: [PATCH v4 1/2] powerpc/uaccess: Implement unsafe_put_user() using 'asm goto' To: Segher Boessenkool Cc: Michael Ellerman , Christophe Leroy , Benjamin Herrenschmidt , LKML , linuxppc-dev , Nicholas Piggin , Paul Mackerras , clang-built-linux 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 Thu, Jun 11, 2020 at 4:53 PM Segher Boessenkool wrote: > > On Thu, Jun 11, 2020 at 03:43:55PM -0700, Nick Desaulniers wrote: > > Segher, Cristophe, I suspect Clang is missing support for the %L and %U > > output templates [1]. > > The arch/powerpc kernel first used the %U output modifier in 0c176fa80fdf > (from 2016), and %L in b8b572e1015f (2008). include/asm-ppc (and ppc64) > have had %U since 2005 (1da177e4c3f4), and %L as well (0c541b4406a6). Thanks for all the references. So it looks like we should have failed sooner, if we didn't support those. Hmm... > > Can you please point me to documentation/unit tests/source for > > these so that I can figure out what they should be doing, and look into > > implementing them in Clang? > > The PowerPC part of > https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html#Machine-Const= raints > (sorry, no anchor) documents %U. I thought those were constraints, not output templates? Oh, The asm statement must also use %U as a placeholder for the =E2=80=9Cupdate=E2=80=9D flag in the corresponding load or store instru= ction. got it. > > Traditionally the source code is the documentation for this. The code > here starts with the comment > /* Write second word of DImode or DFmode reference. Works on regis= ter > or non-indexed memory only. */ > (which is very out-of-date itself, it works fine for e.g. TImode as well, > but alas). > > Unit tests are completely unsuitable for most compiler things like this. What? No, surely one may write tests for output operands. Grepping for `%L` in gcc/ was less fun than I was hoping. > > The source code is gcc/config/rs6000/rs6000.c, easiest is to search for > 'L' (with those quotes). Function print_operand. > > HtH, Yes, perfect, thank you so much! So it looks like LLVM does not yet handle %L properly for memory operands. https://bugs.llvm.org/show_bug.cgi?id=3D46186#c4 It's neat to see how this is implemented in GCC (and how many aren't implemented in LLVM, yikes :( ). For reference, this is implemented in PPCAsmPrinter::PrintAsmOperand() and PPCAsmPrinter::PrintAsmMemoryOperand() in llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp. GCC switches first on the modifier characters, then the operand type. LLVM dispatches on operand type, then modifier. When I was looking into LLVM's AsmPrinter class, I was surprised to see it's basically an assembler that just has complex logic to just do a bunch of prints, so it makes sense to see that pattern in GCC literally calling printf. Not drastically different than my first toy compiler https://nickdesaulniers.github.io/blog/2015/05/25/interpreter-compiler-jit/ (looking back at that post now knowing what relocations are, I feel I should probably add a note that that's a problem that's being solved there. Didn't know it at the time). Some things I don't understand from PPC parlance is the "mode" (preinc, predec, premodify) and small data operands? IIUC the bug report correctly, it looks like LLVM is failing for the __put_user_asm2_goto case for -m32. A simple reproducer: https://godbolt.org/z/jBBF9b void foo(long long in, long long* out) { asm volatile( "stw%X1 %0, %1\n\t" "stw%X1 %L0, %L1" ::"r"(in), "m"(*out)); } prints (in GCC): foo: stw 3, 0(5) stw 4, 4(5) blr (first time looking at ppc assembler, seems constants and registers are not as easy to distinguish, https://developer.ibm.com/technologies/linux/articles/l-ppc/ say "Get used to it." LOL, ok). so that's "store word from register 3 into dereference of register 5 plus 0, then store word from register 4 into dereference of register 5 plus 4?" Guessing the ppc32 abi is ILP32 putting long long's into two separate registers? Seems easy to implement in LLVM (short of those modes/small data operands). https://reviews.llvm.org/D81767 --=20 Thanks, ~Nick Desaulniers