Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1863980pxb; Sat, 2 Apr 2022 06:22:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzLex555jp9w63AqXEnyyHCltVukBPNL/n/Ct1qoOBfoYkCdm0ROq6EtJaave/Il/8SvCY X-Received: by 2002:a63:cf0c:0:b0:380:fb66:fa2a with SMTP id j12-20020a63cf0c000000b00380fb66fa2amr19038525pgg.273.1648905761199; Sat, 02 Apr 2022 06:22:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648905761; cv=none; d=google.com; s=arc-20160816; b=cV0K1+8KV8Sf6Ez7N9lHlHMkQGIArEjP9F8vnaH++fTHL8CNmhMxfrD51KW7Dum6O6 wq9gbhfdULBVBtBhlR1uq40SioEuPMLFve4jRzyjuLT8tY2M94r7JJi17zsY4pSK76DB 7TWvXieErPMKQW5fI1+1P5BsHJZBcd5F9pK31JUdbq8kSePKMOMA9JflssSlac93iefV PZf8x+BDS/ghnreX+BVBRIrdVg1C2t3msss5G9TekoStucgo+tx2JF5E2VKvZyGlPKYK iA+EKPXw5tPSnpCHsV1nZ8ZZ0ihqAhCgs92EmJgofN48K7Oe9NhA3lf31Ic9DitOckT0 fEOA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=+N/PMT9Zj1YyJ6FO/CMlm4DRySkhZlaL+6HUkSuQ7hM=; b=EsRjfzaNl4oe6I0F7kvrL8+PDHlk9rZgubdMLc+GJDytsuZQ+bwv4tnKNzZA3/T5MQ mq1+xGjkBIKT3S7nBPiqazEIUHuZTkOTzaq2ZynA2dh01i7FLz8HhVyjHPyxYOR6NcXC eb/TLFldN0y6CfRTQjQPOpBw0vtS+wLobIln/2wFp1p97V+5553IY2kSTQ55NkOlyg+p G0NehpCWmIPO8aU81bl/zexGq6XGiHh4Ov3/tj7+D9td/qEfLoRYnvhl7sx+1wKptUct QYJRdD+vKSO4Mu58K7PFSG/JIgvjtBpx2SB/25ByFZC9aZNtOEHygeR7JcQpuW2xL9g6 NgzA== ARC-Authentication-Results: i=1; mx.google.com; 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 r29-20020a63fc5d000000b003816043f15esi5042001pgk.851.2022.04.02.06.22.28; Sat, 02 Apr 2022 06:22:41 -0700 (PDT) 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; 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 S232913AbiCaMaB convert rfc822-to-8bit (ORCPT + 99 others); Thu, 31 Mar 2022 08:30:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232868AbiCaM37 (ORCPT ); Thu, 31 Mar 2022 08:29:59 -0400 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C81921044E for ; Thu, 31 Mar 2022 05:28:10 -0700 (PDT) Received: from ip5b412258.dynamic.kabel-deutschland.de ([91.65.34.88] helo=diego.localnet) by gloria.sntech.de with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nZtuJ-0000oT-6f; Thu, 31 Mar 2022 14:28:07 +0200 From: Heiko =?ISO-8859-1?Q?St=FCbner?= To: Christoph Hellwig Cc: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, wefu@redhat.com, liush@allwinnertech.com, guoren@kernel.org, atishp@atishpatra.org, anup@brainfault.org, drew@beagleboard.org, hch@lst.de, arnd@arndb.de, wens@csie.org, maxime@cerno.tech, gfavor@ventanamicro.com, andrea.mondelli@huawei.com, behrensj@mit.edu, xinhaoqu@huawei.com, mick@ics.forth.gr, allen.baum@esperantotech.com, jscheid@ventanamicro.com, rtrauben@gmail.com, samuel@sholland.org, cmuellner@linux.com, philipp.tomsich@vrull.eu, Atish Patra Subject: Re: [PATCH v8 01/14] riscv: prevent null-pointer dereference with sbi_remote_fence_i Date: Thu, 31 Mar 2022 14:28:06 +0200 Message-ID: <2260961.n0HT0TaD9V@diego> In-Reply-To: <20220331095155.GA23422@lst.de> References: <20220324000710.575331-1-heiko@sntech.de> <20220324000710.575331-2-heiko@sntech.de> <20220331095155.GA23422@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset="iso-8859-1" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_NONE, T_SCC_BODY_TEXT_LINE,T_SPF_HELO_TEMPERROR 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 Hi, Am Donnerstag, 31. M?rz 2022, 11:51:55 CEST schrieb Christoph Hellwig: > On Thu, Mar 24, 2022 at 01:06:57AM +0100, Heiko Stuebner wrote: > > The callback used inside sbi_remote_fence_i is set at sbi probe time > > to the needed variant. Before that it is a NULL pointer. > > > > Some users like the flush_icache_*() functions suggest a generic > > functionality, that doesn't depend on a specific boot-stage but > > uses sbi_remote_fence_i as one option to flush other cpu cores. > > > > So they definitely shouldn't run into null-pointer dereference > > issues when called "too early" during boot. > > > > So introduce an empty function to be the standard for the __sbi_rfence > > function pointer until sbi_init has run. > > > > Users of sbi_remote_fence_i will have separate code for the local > > cpu and sbi_init() is called before other cpus are brought up. > > So there are no other cpus present at the time when the issue > > might happen. > > I don't really understand this changelog. If flush_icache_* or > other routines using SBI calls are called too early they won't > do what they are asked to do, which implies a bug in the code. > > So crashing absolutely is the right thing to do here as we don't > really have any other error reporting method available. > > So unless I'm totally misunderstanding what you are saying here: > > Nacked-by: Christoph Hellwig The function is defined as void flush_icache_all(void) { local_flush_icache_all(); if (IS_ENABLED(CONFIG_RISCV_SBI)) sbi_remote_fence_i(NULL); else on_each_cpu(ipi_remote_fence_i, NULL, 1); } so essentially flushes the _local_ icache first and then tries to flush caches on other cores, either via an ipi or via sbi. The remote-fence callback is set correctly during sbi_init(). The other cores are only brought up after sbi-init is done. So it's not really about error reporting but making sure that flush_icache_all() does something sane even when still running on the first core. As I assume the "all" means on all available cores (which would be the core the system booted on). Does this make it clearer what this tries to solve? Heiko