Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1008238pxf; Thu, 18 Mar 2021 17:52:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNGPbBFDKYxXlRrK18AzVCET1D61yrgPA3mMxF3nxpq830Kj8FrNb7WB9u1WtJ2cbP3zig X-Received: by 2002:aa7:de8b:: with SMTP id j11mr6809978edv.363.1616115166947; Thu, 18 Mar 2021 17:52:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616115166; cv=none; d=google.com; s=arc-20160816; b=Hs+gcwQNN9vh8za69/SyXACdnpq0/4gGN85ueKEiY2tC63NwE27mYsV7rmgZqaQ0+4 GgKqacDH5vLueAvaYFb8Y7h60TJgFDhdwk1Hd7FiMMPqM0tKxWfxhJCJAKrUCuvR4ogb 3Djz4Ibj30xZH6UGXHh8Ex7zseOH6IXOOI3mb9KLxG4j5ZfCQ6U00KUI+laOP+0QwmYE 9ctcFDAGa8a96ZB81AiaFjpbZAabmpzZeZgJ8J8Rgfk48txGO5LTEty/ghNMhd8+ysVU xwfbNDayNitxq27Oph/ne4s8Hj7PZ6x03xEG0Z9sVJoWmkupmbzIajW2wPqh+f5oeoGK 87xA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=eG1QzwIi3xEaakEPyWiwcIUMucRPcW0kIWxB+VdX0Ok=; b=Q0B19aw85n1eo+a/ihi25XPGWyAcmYjz8EeBnkZ897UMDr8kjIlZ9nxGdHQFqlsIS2 GTmLQxzYWS9L2YiNMBRewzjXg2a9qNCFNJ2My0hvFVNpvziWnUo5CmPO6pqr/mHg2cRK SyqOI+o7ZSIu9Vuxd2bthO+Fb/InPqIwxRF/vrnRDBWPe4Td8Rv9RIQgOGSnTH6iG2Ei Fe204KytfXfrsY6xAAKo6oM84hwq23zEDiHQdXM1VTUZ0lVJorwvtYtpjVo7VItDg6id nFO0xqsKoshb4EPU4pmQ6kDBjN//d6eNOJ/x1gtuei1tvHBJYzo5Pfw5hTI5IfKrZVNx 7Y6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=RAJG3mFP; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t23si2833143eji.717.2021.03.18.17.52.23; Thu, 18 Mar 2021 17:52:46 -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=@gmail.com header.s=20161025 header.b=RAJG3mFP; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231512AbhCSAso (ORCPT + 99 others); Thu, 18 Mar 2021 20:48:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232221AbhCSAsU (ORCPT ); Thu, 18 Mar 2021 20:48:20 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC889C06174A; Thu, 18 Mar 2021 17:48:18 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id f17so2144236plr.0; Thu, 18 Mar 2021 17:48:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=eG1QzwIi3xEaakEPyWiwcIUMucRPcW0kIWxB+VdX0Ok=; b=RAJG3mFP99nhvmv/KZWxUCdFpGEmKA3rijSW/KwwIvPUb9UZQ6Jg0EyQveb7G4h9fU pkKdfJGMdcIm4HI8uAVUa5Nzv5Zg4BsnDy2d+JmuFQzST8gNpib1b6rpiGNtvsMPhPOC LuJikCi/pTxL5zf9qwXIeLEFzpgbaTtIx5lksikP75lA4DjNhVOHDtGblLuffgfQNSmG iftKfGmNegPkTPItGtRXgUJVFUVTSrMS/FWSdPOvaAyUNDzyCrYvqQgRk1G/AUC4p7UC x53i7x8hpHXAlhD+e1Wa/QaFLzV3EUGQP9EqVnhWX4iPJvyM6NevwDVaL7Kw5/iotfQp ujjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=eG1QzwIi3xEaakEPyWiwcIUMucRPcW0kIWxB+VdX0Ok=; b=BhJ732lROpyQxDoBghK/D82NDhtqDRrXRLXxQSGR4PwDMdvEEIJCspVpYA4yiRKvwG RLWst+8RxItwIybhs5f9X3/sfm+ujcrQcCpZdties2QhWbnWlVYHSndA+beCaBd+FY+L andrKEjOerN33OxiLfGPsGZT8MFHbRd8Sxo3ok6nuYJoKutelQuc4bb0jaejlVxeyQYp z8zYEsv4+8F9VMfyqoZBELocXr4MON6xB4qPFaGq1uOK2KACIqu8Qeix1cQ3qCSDN0OE ziceKYCrJ2xgq06MUnrOyh58Hgu580/D7fSSbRRDCYlA9QUgD3fHQjXTGvua6aoI79M4 7YGA== X-Gm-Message-State: AOAM530ooVV2YCKoSJWJjoMwK6nEXqbSn78euKr0PzLpd965NEMYMOrQ /mHsBXmK/Xv7wulY8uSC16w= X-Received: by 2002:a17:902:bf92:b029:e6:bc0:25ac with SMTP id v18-20020a170902bf92b02900e60bc025acmr12452727pls.49.1616114898109; Thu, 18 Mar 2021 17:48:18 -0700 (PDT) Received: from [10.230.29.202] ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id g2sm3388274pfi.28.2021.03.18.17.48.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 18 Mar 2021 17:48:17 -0700 (PDT) Subject: Re: [PATCH] swiotlb: Add swiotlb=off to disable SWIOTLB To: Robin Murphy , linux-kernel@vger.kernel.org, Christoph Hellwig Cc: Jonathan Corbet , opendmb@gmail.com, "Paul E. McKenney" , Konrad Rzeszutek Wilk , Mauro Carvalho Chehab , Viresh Kumar , Randy Dunlap , "open list:DOCUMENTATION" , Peter Zijlstra , "open list:SWIOTLB SUBSYSTEM" , Andrew Morton , Mike Kravetz , Thomas Gleixner References: <20210318191816.4185226-1-f.fainelli@gmail.com> <16d1c66f-5451-2515-af73-a6b44d996e92@arm.com> <3dd81519-4a73-efb8-abf0-0b766f993a8b@arm.com> From: Florian Fainelli Message-ID: Date: Thu, 18 Mar 2021 17:48:12 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <3dd81519-4a73-efb8-abf0-0b766f993a8b@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/18/2021 4:35 PM, Robin Murphy wrote: > On 2021-03-18 21:31, Florian Fainelli wrote: >> >> >> On 3/18/2021 12:53 PM, Robin Murphy wrote: >>> On 2021-03-18 19:43, Florian Fainelli wrote: >>>> >>>> >>>> On 3/18/2021 12:34 PM, Robin Murphy wrote: >>>>> On 2021-03-18 19:22, Florian Fainelli wrote: >>>>>> >>>>>> >>>>>> On 3/18/2021 12:18 PM, Florian Fainelli wrote: >>>>>>> It may be useful to disable the SWIOTLB completely for testing or >>>>>>> when a >>>>>>> platform is known not to have any DRAM addressing limitations >>>>>>> what so >>>>>>> ever. >>>>> >>>>> Isn't that what "swiotlb=noforce" is for? If you're confident that >>>>> we've >>>>> really ironed out *all* the awkward corners that used to blow up if >>>>> various internal bits were left uninitialised, then it would make >>>>> sense >>>>> to just tweak the implementation of what we already have. >>>> >>>> swiotlb=noforce does prevent dma_direct_map_page() from resorting to >>>> the >>>> swiotlb, however what I am also after is reclaiming these 64MB of >>>> default SWIOTLB bounce buffering memory because my systems run with >>>> large amounts of reserved memory into ZONE_MOVABLE and everything in >>>> ZONE_NORMAL is precious at that point. >>> >>> It also forces io_tlb_nslabs to the minimum, so it should be claiming >>> considerably less than 64MB. IIRC the original proposal *did* skip >>> initialisation completely, but that turned up the aforementioned issues. >> >> AFAICT in that case we will have iotlb_n_slabs will set to 1, which will >> still make us allocate io_tlb_n_slabs << IO_TLB_SHIFT bytes in >> swiotlb_init(), which still gives us 64MB. > > Eh? When did 2KB become 64MB? IO_TLB_SHIFT is 11, so that's at most one > page in anyone's money... Yes, sorry incorrect shift applied here. Still, and I believe this is what you mean below, architecture code setting swiotlb_force = SWIOTLB_NO_FORCE does not result in not allocating the SWIOTLB, because io_tlb_nslabs is still left set to 0 so swiotlb_init() will proceed with allocating the default size. > >>>>> I wouldn't necessarily disagree with adding "off" as an additional >>>>> alias >>>>> for "noforce", though, since it does come across as a bit wacky for >>>>> general use. >>>>> >>>>>>> Signed-off-by: Florian Fainelli >>>>>> >>>>>> Christoph, in addition to this change, how would you feel if we >>>>>> qualified the swiotlb_init() in arch/arm/mm/init.c with a: >>>>>> >>>>>> >>>>>> if (memblock_end_of_DRAM() >= SZ_4G) >>>>>>       swiotlb_init(1) >>>>> >>>>> Modulo "swiotlb=force", of course ;) >>>> >>>> Indeed, we would need to handle that case as well. Does it sound >>>> reasonable to do that to you as well? >>> >>> I wouldn't like it done to me personally, but for arm64, observe what >>> mem_init() in arch/arm64/mm/init.c already does. > > In fact I should have looked more closely at that myself - checking > debugfs on my 4GB arm64 board actually shows io_tlb_nslabs = 0, and > indeed we are bypassing initialisation completely and (ab)using > SWIOTLB_NO_FORCE to cover it up, so I guess it probably *is* safe now > for the noforce option to do the same for itself and save even that one > page. OK, I can submit a patch that does that. 5.12-rc3 works correctly for me here as well and only allocates SWIOTLB when needed which in our case is either: - we have DRAM at PA >= 4GB - we have limited peripherals (Raspberry Pi 4 derivative) that can only address the lower 1GB Now let's see if we can get ARM 32-bit to match :) -- Florian