Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp286459rwj; Thu, 22 Dec 2022 07:45:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXvGzZ/Hj80UTLl+bLWDsBlijVsA8kgu1j6JLzBRiCZYkBgpf3oEAhOYggDSrz8cXqFfuyi2 X-Received: by 2002:a17:906:5289:b0:82b:61db:92b8 with SMTP id c9-20020a170906528900b0082b61db92b8mr4814450ejm.57.1671723952972; Thu, 22 Dec 2022 07:45:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671723952; cv=none; d=google.com; s=arc-20160816; b=hkFKap4i6vEh9oaj3Kz0pOZ0uqQlimOMA0fSb/Y6/P7EbJO42QKFoC/Z9ZXmxz0VjX iX8hHMaXqtyQx2mkqyf++jCX9R8wPmL9XiZmkTJ30h+T6LelvGsA/nbsmt84fwbfTrfZ NdIFOE6tUvpJhnGbhl4yM8Xefj19PNCZ+mTcFK6cMjFggyHEBiR5YTBk1yY+rxElHp2+ HFpewfwBAyL5fN6DmdwKavIXbw2GXA1jMawvqU7rCS//HQWBrTH/E1NPTo70Zm4hujk/ gY3PsXsedOuQ1IdnakEVicDKgWW0GHI8HWXqk5s+g4EpYtQmTj0RfHoLrLQrhiX7ayMa +5Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=is8eOCOUHh28WCvnVkZFiUBMmSnyVVi5EENP2Q9yDrQ=; b=qpd9lR0oYJ66hiAtbPvBY798V/4l95OnhininFC5Lu3yW7omlTYGvmCWdcB59y4UU/ 0EZ5Pk32nvfTNFR79w9nDjU6hwkXkl/wpy+AdrZTkFdSDhwnf9r6iRaLILPamNQjqmeq yIitU4x1CFFCWHCJkAtljVBCPSKOdoftqvk8bc4xXODKkmzdyHxqnbdDlqYDIeM/fzI/ fRf/tVg/4UfZONbd15A8HMIsgaTgH99Phk/5rj8whpsXjITjsMP99gDKFHP7xY2A4pQP dtfVw1Im2Uj6KlxtQ3tsqtlu7aNkQnSAzmHtqQWzaCSX2vUBqQEZapBaiwnTmXBAIB0c GB1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=e3zjxSIL; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dt9-20020a170907728900b0073ce34d1a13si685221ejc.499.2022.12.22.07.45.36; Thu, 22 Dec 2022 07:45:52 -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=@google.com header.s=20210112 header.b=e3zjxSIL; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235507AbiLVPZm (ORCPT + 67 others); Thu, 22 Dec 2022 10:25:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235217AbiLVPZQ (ORCPT ); Thu, 22 Dec 2022 10:25:16 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AA0631EFA for ; Thu, 22 Dec 2022 07:23:56 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id o5-20020a05600c510500b003d21f02fbaaso4128400wms.4 for ; Thu, 22 Dec 2022 07:23:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=is8eOCOUHh28WCvnVkZFiUBMmSnyVVi5EENP2Q9yDrQ=; b=e3zjxSILoAIDIfAytzMAfpjBCocaoXQXsl0FxH7xFOeaqnr0pNBnBwAM1lTUCs5zkK vv+9o0GtlWFvdXt/0rZrXtjsGc8h4651EHPub2AA+3u4Q+UjIfeO6+61dCqfaV7FvsoQ mOAse3Nc0o3rmP4k7XAHcwlAcHspEBBCGYv5rja7KZJ5od8kusnTJjRlTkaDC/m+Fi8O 6ImxHM+LzjM39rxUC0OjOX6usp1rYgMhEgKzQ+NAHCDqeEQOg8AIZqbtJkU74kJao7gS URsoClthBsw3ctdnTkJqkGWy5oKUqsj0Y8gtxJGRr9GrwVd5k/90bA5s4bxAEZ6Md9Fp +BJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=is8eOCOUHh28WCvnVkZFiUBMmSnyVVi5EENP2Q9yDrQ=; b=25Tj4U2y/iUxOeyCBUSg16ltnYKabeteNNdt9qFRjS0Zll/T/p+gY/u9R+uYsuHkV9 yfWEAw+9hMl9Qp7InW4iw/IMPhiniuoIdGl2M8OwOWygpeRHWNsKdL28fRzxaoGRQUl2 iNuuixboBkk1zAhTN8Eiih7jNVZ5pvbl0imUgCqK8/8j6ChTgaPW1niuux7KKBfDQVmI A8OuCV2Wz+fhmV88wGjLJxavLk3GqHJMAvRvVNsPS93+gosjcYpJ5IMsHmo+lguqJuPQ LA+tmF2tDG3acJuR2/azu7einrNysJ7r4F1HbmI4ZqSyulWezRiSxdRbRtL2u3kMVQLg ktNA== X-Gm-Message-State: AFqh2kqWgcbnh0fmXmaiGEMs8LZFXj4X/h1DNyOfQ6PY4lJzzeonwg/o 55a/cBI6CQJQF5lzmgq4IIBlfnrb2rR2gpt2ewlP+Q== X-Received: by 2002:a7b:cd94:0:b0:3d3:4b1a:974b with SMTP id y20-20020a7bcd94000000b003d34b1a974bmr577660wmj.113.1671722635094; Thu, 22 Dec 2022 07:23:55 -0800 (PST) MIME-Version: 1.0 References: <20221216185012.2342675-1-abdulras@google.com> In-Reply-To: From: Saleem Abdulrasool Date: Thu, 22 Dec 2022 07:23:43 -0800 Message-ID: Subject: Re: [PATCH] riscv: avoid enabling vectorized code generation To: Bin Meng Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Thu, Dec 22, 2022 at 1:41 AM Bin Meng wrote: > > Hi, > > On Thu, Dec 22, 2022 at 1:39 AM Saleem Abdulrasool wrote: > > > > On Wed, Dec 21, 2022 at 8:17 AM Bin Meng wrote: > > > > > > Hi, > > > > > > On Sat, Dec 17, 2022 at 3:12 AM Saleem Abdulrasool wrote: > > > > > > > > The compiler is free to generate vectorized operations for zero'ing > > > > memory. The kernel does not use the vector unit on RISCV, similar to > > > > architectures such as x86 where we use `-mno-mmx` et al to prevent the > > > > implicit vectorization. Perform a similar check for > > > > `-mno-implicit-float` to avoid this on RISC-V targets. > > > > > > > > Signed-off-by: Saleem Abdulrasool > > > > --- > > > > arch/riscv/Makefile | 4 ++++ > > > > 1 file changed, 4 insertions(+) > > > > > > > > diff --git a/arch/riscv/Makefile b/arch/riscv/Makefile > > > > index 0d13b597cb55..68433476a96e 100644 > > > > --- a/arch/riscv/Makefile > > > > +++ b/arch/riscv/Makefile > > > > @@ -89,6 +89,10 @@ KBUILD_AFLAGS_MODULE += $(call as-option,-Wa$(comma)-mno-relax) > > > > # architectures. It's faster to have GCC emit only aligned accesses. > > > > KBUILD_CFLAGS += $(call cc-option,-mstrict-align) > > > > > > > > +# Ensure that we do not vectorize the kernel code when the `v` extension is > > > > +# enabled. This mirrors the `-mno-mmx` et al on x86. > > > > +KBUILD_CFLAGS += $(call cc-option,-mno-implicit-float) > > > > > > This looks like an LLVM flag, but not GCC. > > > > Correct, this is a clang flag, though I imagine that GCC will need a > > similar flag once it receives support for the V extension. > > > > > Can you elaborate what exact combination (compiler flag and source) > > > would cause an issue? > > > > The particular case that I was using was simply `clang -target > > riscv64-unknown-linux-musl -march=rv64gcv` off of main. > > > > > From your description, I guess it's that when enabling V extension in > > > LLVM, the compiler tries to use vector instructions to zero memory, > > > correct? > > > > Correct. > > Thanks for the confirmation. > > > > > > Can you confirm LLVM does not emit any float instructions (like F/D > > > extensions) because the flag name suggests something like "float"? > > > > The `-mno-implicit-float` should disable any such emission. I assume > > that you are worried about the case without the flag? I'm not 100% > > certain without this flag, but the RISCV build with this flag has been > > running smoothly locally for a while. > > > > > > I still have some questions about the `-mno-implicit-float` option's behavior. > > - If this option is not on, does the compiler emit any F/D extension > instruction for zero'ing memory when -march=rv64g? I want to know > whether the `-mno-implicit-float` option only takes effect when "v" > appears on the -march string. AFAIK, and from a quick test, no, it will not. That also makes sense since the F/D/Q handling is not as likely to be useful for generating a 0-filled array. No, the use of `-mno-implicit-float` is not guarded by the use of the vector extension, but it does only impact the vectorized code generation (the loop vectorizer, load/store vectorizer, and SLP vectorizer). > - If the answer to the above question is no, I wonder why the option > is called `-mno-implicit-float` as float suggests the FPU usage, but > actually it is about vectorization. The Clang documentation says > almost nothing about this option. The flag itself is from GCC, it was added for the ARM architecture, to prefer using the scalar core over the VFP register set as ARM uses the VFP for vectorized operations. As it so happens, internally in LLVM, the loop vectorizer uses the (internal) `NoImplicitFloat` function attribute to prevent the loop from being vectorized, and the flag that controls this is exposed as `-mimplicit-float` and `-mno-implicit-float`. > > > > + > > > > ifeq ($(CONFIG_STACKPROTECTOR_PER_TASK),y) > > > > prepare: stack_protector_prepare > > > > stack_protector_prepare: prepare0 > > > > -- > > Regards, > Bin