Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3096606rwb; Fri, 9 Dec 2022 09:55:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf5TwsdorFYum8CMJgWBofdap09She2KbWSrCjoyelWUjPhvGFQq88RNWKlQJFb64yYFQSvS X-Received: by 2002:a17:906:5213:b0:7c1:3125:9564 with SMTP id g19-20020a170906521300b007c131259564mr4828082ejm.8.1670608516513; Fri, 09 Dec 2022 09:55:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670608516; cv=none; d=google.com; s=arc-20160816; b=qd8iE/S2Uz/SS9W/Adr/z5A6z7rRatnKDxgCAwyUPWw1v4OLywB9vkuymOcUEfQWiO ybXc5PldBbdZCH+lSjAkBFVx0irJ2ldVPcrp89XJ77ZtWulac4M4dLLFo29ggYgZ1dIV OP6LRK4fYwEzS0HLAEDXlMeRfTfpMuoV0fNnGKaDqXNpRvA19m9vT1SSFATn26//TQ/d YTg04LQYG3x2BUyLI0j1Yfijixw9qiGbvH7HGZNpn2AZHqLcHUWWb9A6lY0C4fZUT7zI cyA5Oe/Fm6B2oGEVVFSGDgDJPU1iU8dRXDAtuqvtHW+avUK1tKCsw4t8wfM4eFkeUC5k 3TGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:to:from:cc:in-reply-to:subject:date:dkim-signature; bh=i3ftz22T4PBLAKYuAEy8MSiyeSsUvlcVd5LGzrsdS20=; b=RsGBSlMq7aUrR2hha6rBME7Cnphb/xTShCqyBhLywXXqdWDu6GlzvGhnVosS1TnhAr bDwId6EGYR1gu8mwZ1hPLYh/txNUc6GSLF11CeimrnAa0eS3qw5j5WSjfx2evF6U/B4r C6H+BdTT7VMkHxbuR3YR/hhpsZTup4BZN+hkJXraBUoPqYpsvloylvwPUx9c4V7XoRP5 IhXBOHO78CpYFZ92Unot1O9HQrCudj91Hfk/nOJTqueqKhIIzuTYjoC3EVl9ZmXON8CS 5jMYw1BHy9/+yhX+XulGiP5a/4dDA1jFV2avU9crgrkp4xXufw5hPhID13jioAp0378J ehlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dabbelt-com.20210112.gappssmtp.com header.s=20210112 header.b=o9iqnF1A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw10-20020a170906478a00b007c0d6091781si305126ejc.639.2022.12.09.09.54.58; Fri, 09 Dec 2022 09:55:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@dabbelt-com.20210112.gappssmtp.com header.s=20210112 header.b=o9iqnF1A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230143AbiLIRWJ (ORCPT + 75 others); Fri, 9 Dec 2022 12:22:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230153AbiLIRVt (ORCPT ); Fri, 9 Dec 2022 12:21:49 -0500 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABAE1101C2 for ; Fri, 9 Dec 2022 09:21:46 -0800 (PST) Received: by mail-pj1-x1032.google.com with SMTP id 3-20020a17090a098300b00219041dcbe9so5623751pjo.3 for ; Fri, 09 Dec 2022 09:21:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dabbelt-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:from:to:cc:subject:date:message-id :reply-to; bh=i3ftz22T4PBLAKYuAEy8MSiyeSsUvlcVd5LGzrsdS20=; b=o9iqnF1AFARrXLpxgvQ9MMiwrWgg/fYr9Im7EHbyQw4/mk6D1BEdl8J94wSiC8a3yw yijrOJXrMtAjL8BGmZ8C68RwIt10n1LBw/ki6zzN3MZCxq2mB36FcSScnkxzaj+pfTbA O/gsspSRNgHDKTYgpX8DbCDjxnFRGO7eSPD8kjXLRb3fKk1/nbh5+dST1MLO8dmvVYGc rRgG+r8bE1qrrt/QkqSARea+Nt7W8FMhF4Tjsgh9wGR0uB1216RAXtZSviYKd1yZNafv nToYZR1UgCXCODgPege/HytqhANmxMkBE1nxm6GvWwkTtNy0NY3nEydwEW00AvGvToMe xqSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:to:from:cc :in-reply-to:subject:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=i3ftz22T4PBLAKYuAEy8MSiyeSsUvlcVd5LGzrsdS20=; b=f+zaVfWEyaqkB7N+UpNaXBj9WEru5CpdsIvRJ6eYDCS7Tu/Cgn9w2j9I5AtKeLzEc9 Rhc7nh7ytYx9Scv+NFiNrmagjX9uWp9NDQ1q7giA7us07auCDUa6LZEoMPN+rOxOaZ6L DuWrw9WTAA8JeDlIci5PJsXcJwnwBGSOAq5HB61jLH/w0hAv7droXd5zqJXR3meRUsSz M3vJEgq3jCZKdlw3oAtgyUQjqd9tMSYweiS6ccdq1veI8SK1tuPu9Hwixwh9qXL3yJF2 Et0bMNRSJLrqP057GGoCAuJog3ZWyRUe2a6SuupyMK0bsyjkhJlPZ4pYumtyNioWD65E UX+Q== X-Gm-Message-State: ANoB5pnLy6nkdHMECy/q+ncfKIwXHf+Dh2F2msgyATVDLfLJV7rlhKSW ocTK1DQ9+E9NrEdfkUMeLgo8PQ== X-Received: by 2002:a17:90a:d515:b0:219:c1e8:114d with SMTP id t21-20020a17090ad51500b00219c1e8114dmr6508249pju.26.1670606506081; Fri, 09 Dec 2022 09:21:46 -0800 (PST) Received: from localhost ([135.180.226.51]) by smtp.gmail.com with ESMTPSA id kk10-20020a17090b4a0a00b001fde655225fsm10884328pjb.2.2022.12.09.09.21.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Dec 2022 09:21:45 -0800 (PST) Date: Fri, 09 Dec 2022 09:21:45 -0800 (PST) X-Google-Original-Date: Fri, 09 Dec 2022 09:21:41 PST (-0800) Subject: Re: RISCV Vector unit disabled by default for new task (was Re: [PATCH v12 17/17] riscv: prctl to enable vector commands) In-Reply-To: <87zgbwk9t4.fsf@oldenburg.str.redhat.com> CC: Andrew Waterman , Vineet Gupta , stillson@rivosinc.com, Paul Walmsley , anup@brainfault.org, atishp@atishpatra.org, guoren@kernel.org, Conor Dooley , greentime.hu@sifive.com, vincent.chen@sifive.com, andy.chiu@sifive.com, arnd@kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, bjorn@kernel.org, libc-alpha@sourceware.org, christoph.muellner@vrull.eu, Aaron Durbin , linux@rivosinc.com From: Palmer Dabbelt To: fweimer@redhat.com Message-ID: Mime-Version: 1.0 (MHng) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 09 Dec 2022 05:04:23 PST (-0800), fweimer@redhat.com wrote: > * Darius Rad: > >> On Fri, Dec 09, 2022 at 01:32:33PM +0100, Florian Weimer via Libc-alpha wrote: >>> * Darius Rad: >>> >>> > On Fri, Dec 09, 2022 at 11:02:57AM +0100, Florian Weimer wrote: >>> >> * Andrew Waterman: >>> >> >>> >> > This suggests that ld.so, early-stage libc, or possibly both will need >>> >> > to make this prctl() call, perhaps by parsing the ELF headers of the >>> >> > binary and each library to determine if the V extension is used. >>> >> >>> >> If the string functions use the V extension, it will be enabled >>> >> unconditionally. So I don't see why it's okay for libc to trigger this >>> >> alleged UAPI change, when the kernel can't do it by default. >>> >> >>> > >>> > Because the call to enable can fail and userspace needs to deal with that. >>> >>> Failure is usually indicated by an AT_HWCAP or AT_HWCAP2 bit remaining >>> zero, or perhaps a special CPU register (although that is more unusual). >> >> That would indicate that the extension is not present, which is one of, but >> not the only way it can fail. > > I think you should bring down the number of failure modes. HWCAP has > the advantage that it communicates kernel/hypervisor/firmware/CPU > support in a single bit, which simplifies the programming model and > avoids hard-to-detect bugs. It's not clear why it would be beneficial > to continue on ENOMEM failures here because the system must clearly be > in bad shape at this point, and launching a new process is very unlikely > to improve matters. So I think the simpler programming model is the way > to go here. > >> The vector extension relies on dynamically allocated memory in the kernel, >> which can fail. The issue I'm worried about is that V needs more space in the ucontext-type structures. We have an extensibility scheme there so we think it can be made to work, but IIUC we'll need glibc to be updated to handle the extended contexts in order to avoid losing state when doing ucontext-related operations like signal handling. I don't see a way to handle that with just HWCAP, as we essentially need some bi-directional communicaton between userspace and the kernel so they can both decide to turn on V. I don't think we strictly need a system call to do that, we kicked around the idea of encoding this in the ELF, but there's a lot of flavors of vector in RISC-V and we've had trouble trying to encode these in binaries before so it seems easier to just use the syscall. > But this failure can be reported as part of execve and clone. > >> It also provides the opportunity for the kernel to deny access to the >> vector extension, perhaps due to administrative policy or other future >> mechanism. > > HWCAP can do this, too. > > Thanks, > Florian