Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp1372362rdh; Fri, 24 Nov 2023 10:52:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvRfUub5fat0kQJ7wXdMOio0Rct+3kXr9Z9Lv/rhdNzzM4wyKXOQXMrsjd99BoIkFvFx64 X-Received: by 2002:a17:90b:1a89:b0:285:9912:a4c4 with SMTP id ng9-20020a17090b1a8900b002859912a4c4mr2001106pjb.41.1700851979082; Fri, 24 Nov 2023 10:52:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700851979; cv=none; d=google.com; s=arc-20160816; b=UH7XERPkCRtM9wRqDBEwoyDKgpjrCgaoOn2P5qFF8Inub5AS+pBuAmHPitVh43Z73/ gIgMmOkSBcSp5pVAu+GDKsNMYFLQKZ9pgKyMWYbNKQJFP3wfj4YNtmM/AO/OudlCQ91s gJHGXr1XjWI8a15DJ+4vSZeiQHUDDPR94ylCGB9mvqdKdqWP5JA2IBT+zBg3rVBnl2ZI MpC/BUpOihbDkVjnrvUjGeq2/nA3v6s5iXhcJJc1Djwrv/Npe6i1RnXY6ZgUXnHfOHew oFLPnQTa4X5ojyCB9tq9Icte1dJu3/sieNVZCw65sSEAfrs5fUbRYQG8sk9VxeQvzNX0 RxLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=qDe7TowA3pJtD1uz4Cwe7404XRpp6gaX2/cNA2FANqc=; fh=77uBfpBURjbGymmIhzdkPTZwDQp990lfLa12aG1yD8Q=; b=i0OaiFLIVkwz7UsNEeFsBJcFM5IffpCiaNbhtG9WufWqaPibu5BCdt3JMvChDIxDNE b8Hu+YKMidMx/LzQIl0iK3R4/CrbnuOb9vORYw89fJdMOXILV73FtDFkAYMygXeg1SSw WhplK+9AeJpz/ushXVUGXKov2USl/l8o+/fR33odM84zGtMAm5lPZSmAKjrXfe0gaiCM +VZG6ABjhZGv/O+KJMMbf8Cncv/nWKzk/kXQj1xk9JQnooVs0VXmIMSBwZeZQpX81zYa bfRR7LGWTiAkQKc7bK+HyXaaYpvxG+ivCRqJL5zS4WDCNf7/Whh0XVjuXqO51SK8J3C9 WQKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ePFQEcgv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id ca20-20020a17090af31400b00280ca0a527fsi4526205pjb.114.2023.11.24.10.52.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 10:52:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ePFQEcgv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 387F58035E4A; Fri, 24 Nov 2023 10:52:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345782AbjKXSwl (ORCPT + 99 others); Fri, 24 Nov 2023 13:52:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345717AbjKXSwk (ORCPT ); Fri, 24 Nov 2023 13:52:40 -0500 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDF9119B1; Fri, 24 Nov 2023 10:52:45 -0800 (PST) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2c876f1e44dso27787511fa.0; Fri, 24 Nov 2023 10:52:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700851964; x=1701456764; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=qDe7TowA3pJtD1uz4Cwe7404XRpp6gaX2/cNA2FANqc=; b=ePFQEcgvIshJ2JjcsayMwHRuJE4Rw+9J0HqH565+xA5siEZmTMEMQLNP/9Tu7VoJuc tYcbT4wzIzlxgDZQTd0de+pZF741t+WI4r/yJOQeN9FB+F57QSioEusp1hwZIXTQIQyt tSdTMS8D82dozSfgz51Oz5irXQ3pqsHe3WigDGQHSIU6Xmg/lNSKz2bYxoOZ2OfflxvH 7MpqosJ6kBhUt0jP45umdsdhFc9Umavvg/kHW22zdb3udIB5/AFsXxtZur5o1ffJZEe6 oEwtF83/Go3bPpmCSZ+WieF/VSe2oGpTZXdu4Fpo+BKgQ1zoOzMshxB0DNMZ0zJVFKbg sVAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700851964; x=1701456764; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qDe7TowA3pJtD1uz4Cwe7404XRpp6gaX2/cNA2FANqc=; b=u72u50P75i2cvdYU7/MRJ+vk21ZWX3UKGMtFVBFs9KO8OkLx7ejieOhWvYutdTZ1AN hNH0XPVIht/F3gMwtas39+yzCKyf+AO4Y51aUiLDCsrtzF5r7k+03Ja+oprRREuKe28e 9IgGK4tSX47KqSWfLaHNNrFAFUaMaBuw4Fk4aFcHKKhxCU0Q74pbELe0pSO2UL3TKDUg Im0kJd7w6P38Om0D6kLWwSkP1ydO/dil3oe3jsMLobKxQtNyrIOh1CUUOJIjjZ1oQsAq E7tAO+wGPQtEqHUBVBLCSsNOaobm2W6wv2r/5XdWT0ImsZgJaq96mCoUpT1oNv/gSne+ O4Dw== X-Gm-Message-State: AOJu0YzR96GlusWdtQUmx39dcZZC2FnlmdsNh/upeocbCq/h19v759Gh fyi22+tQHq2bANGCh0tHsEG2IDJ7/kjAXw== X-Received: by 2002:a2e:b2d1:0:b0:2bc:d5f1:b9cf with SMTP id 17-20020a2eb2d1000000b002bcd5f1b9cfmr3058491ljz.27.1700851963901; Fri, 24 Nov 2023 10:52:43 -0800 (PST) Received: from mobilestation ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id f6-20020a2eb5a6000000b002b47a15a2eesm585074ljn.45.2023.11.24.10.52.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 10:52:43 -0800 (PST) Date: Fri, 24 Nov 2023 21:52:40 +0300 From: Serge Semin To: Jiaxun Yang , Thomas Bogendoerfer Cc: Arnd Bergmann , Andrew Morton , Mike Rapoport , Matthew Wilcox , Tiezhu Yang , Huacai Chen , Yinglu Yang , Alexey Malahov , Aleksandar Rikalo , Aleksandar Rikalo , Dragan Mladjenovic , Chao-ying Fu , Marc Zyngier , "linux-mips@vger.kernel.org" , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/7] mips: dmi: Fix early remap on MIPS32 Message-ID: <3iksuovvsln3cw3xpmjd7f7xixfvwaneu4ok56fnookvyolpco@wrxxew3thgnq> References: <20231122182419.30633-1-fancer.lancer@gmail.com> <20231122182419.30633-2-fancer.lancer@gmail.com> <8ca730b9-fa8c-46ea-bdc5-158da0f29c3a@app.fastmail.com> <245d3985-9085-4be0-8c74-d95d06334584@app.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <245d3985-9085-4be0-8c74-d95d06334584@app.fastmail.com> X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 24 Nov 2023 10:52:56 -0800 (PST) On Thu, Nov 23, 2023 at 05:33:31PM +0000, Jiaxun Yang wrote: > > > 在2023年11月23日十一月 下午4:07,Thomas Bogendoerfer写道: > > On Thu, Nov 23, 2023 at 03:07:09PM +0000, Jiaxun Yang wrote: > >> > [...] > > > > the problem with all 32bit unmapped segments is their limitations in > > size. But there is always room to try to use unmapped and fall back > > to mapped, if it doesn't work. But I doubt anybody is going to > > implement that. > > Yep, I guess fallback should be implemented for ioremap_cache as well. > > > > >> >> AFAIK for Loongson DMI is located at cached memory so using ioremap_uc > >> >> blindly will cause inconsistency. > >> > > >> > why ? > >> > >> Firmware sometimes does not flush those tables from cache back to memory. > >> For Loongson systems (as well as most MTI systems) cache is enabled by > >> firmware. > > > > kernel flushes all caches on startup, so there shouldn't be a problem. > > Actually dmi_setup() is called before cpu_cache_init(). To preliminary sum the discussion, indeed there can be issues on the platforms which have DMI initialized on the cached region. Here are several solutions and additional difficulties I think may be caused by implementing them: 1. Use unmapped cached region utilization in the MIPS32 ioremap_prot() method. This solution a bit clumsy than it looks on the first glance. ioremap_prot() can be used for various types of the cachability mapping. Currently it's a default-cacheable CA preserved in the _page_cachable_default variable and Write-combined CA saved in boot_cpu_data.writecombine. Based on that we would have needed to use the unmapped cached region utilized for the IO-remaps called with the "_page_cachable_default" mapping flags passed only. The rest of the IO range mappings, including the write-combined ones, would have been handled by VM means. This would have made the ioremap_prot() a bit less maintainable, but still won't be that hard to implement (unless I miss something): --- a/arch/mips/mm/ioremap.c +++ b/arch/mips/mm/ioremap.c /* - * Map uncached objects in the low 512mb of address space using KSEG1, - * otherwise map using page tables. + * Map uncached/default-cached objects in the low 512mb of address + * space using KSEG1/KSEG0, otherwise map using page tables. */ - if (IS_LOW512(phys_addr) && IS_LOW512(last_addr) && - flags == _CACHE_UNCACHED) - return (void __iomem *) CKSEG1ADDR(phys_addr); + if (IS_LOW512(phys_addr) && IS_LOW512(last_addr)) { + if (flags == _CACHE_UNCACHED) + return (void __iomem *) CKSEG1ADDR(phys_addr); + else if (flags == _page_cachable_default) + return (void __iomem *) CKSEG0ADDR(phys_addr); + } Currently I can't figure out what obvious problems it may cause. But It seems suspicious that the cacheable IO-mapping hasn't been implemented by the unmapped cacheable region in the first place. In anyway this solution looks more dangerous than solution 2. because it affects all the MIPS32 platforms at once. 2. Convert dmi_remap_early() to ioremap_uc() (actually just ioremap() as noted by Arnd). As Jiaxun correctly noted this may cause problems on the platforms which don't flush caches before jumping out to the kernel. Thomas said that kernel flushes the caches early on boot, but Jiaxun noted that it's still done after early DMI setup. So the issue with solution 2 is that the setup_arch() method calls dmi_setup() before it flushes the caches by means of the cpu_cache_init() method. I guess it can be fixed just by moving the dmi_setup() method invocation to be after the cpu_cache_init() is called. This solution looks much less invasive than solution 1. So what do you think? What solution do you prefer? Perhaps alternative? -Serge(y) > > Thanks > > > > Thomas. > > > > -- > > Crap can work. Given enough thrust pigs will fly, but it's not necessarily a > > good idea. [ RFC1925, 2.3 ] > > -- > - Jiaxun