Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp159901rwl; Thu, 6 Apr 2023 16:39:23 -0700 (PDT) X-Google-Smtp-Source: AKy350a95DnFtu27wSY65yjB+hvhveKcFYcZwugM/xlri3han3lAMe6syjByF9n/fvkKKID2M0Cb X-Received: by 2002:a17:906:4e07:b0:8a5:8620:575 with SMTP id z7-20020a1709064e0700b008a586200575mr536013eju.3.1680824363446; Thu, 06 Apr 2023 16:39:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680824363; cv=none; d=google.com; s=arc-20160816; b=eK8u+vssDamWoDUS4sOVup1oUPwWtV4agB3LoaHmE+UTsVHSXCa2uvZi7MOtH5uq5Q jdTstkhFItN1ItSVC3lZ+HPIXZXxru0TSTFW1Bo7orjhfxFe+TFPl/E7Ud1wdll0/eRy A8kPIRRLYAoZfSUMESn/TTervK0k5BMYgJGaVPa9Z58X8QLIT5+adOahwGRxlyZgfV7W oCv3DqeZ5Y1mY2Ef41gqbUx0NBAZi+OOFhp66yv7wiC6yYvUj2K16uBMjYxUC6ZaoxIU 4zIQUPsV2hJHxxXM/FVKXFMr0ciLqCGfHiPX1FPYPrUTZwBS/ruB7E0aDhKut/hA8SMv zdnQ== 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:subject:cc:to:from:date :dkim-signature; bh=4xcxqI13YblR5naM0xfJF4hAuiaf6zTvAqeX0dtk2i0=; b=moWMxV6XifRd8ab1/b1P2I11dTTeTaa6NULcBCyAm9H8GYwPeNMzi8bIqQ9/eboMJt vtQfss65167IgcYtXGa6Ygjg9aWtUS3jEnSZoWvXVfXHay/diMDkdaBgNfyS6Vziik/n 89wZOVbz60aTA1oA6ZtkYm7PkGtYKeTgFiFHYQ3NRyU9atsyeU4Kh418ln76heR4W25U 2rktb4RRNjI9zqgzMtS62XWPBhApH681NpcPNfMyRh32+vdZKaKlWSZBg222fF7Hg0QQ BIbCOz7r0yrL4fGVyP4I4wR/GtoVKhxkSueQ5UjmM5k0k+glljsqo8YxobycQQ6hQIVG hNPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=1fs25dyW; 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 f14-20020a170906048e00b00933b7f95468si2235986eja.277.2023.04.06.16.38.57; Thu, 06 Apr 2023 16:39:23 -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; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=1fs25dyW; 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 S230407AbjDFXi1 (ORCPT + 99 others); Thu, 6 Apr 2023 19:38:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229626AbjDFXi0 (ORCPT ); Thu, 6 Apr 2023 19:38:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACCFB7EDC for ; Thu, 6 Apr 2023 16:38:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2271F64B44 for ; Thu, 6 Apr 2023 23:38:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B04AC433EF; Thu, 6 Apr 2023 23:38:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1680824303; bh=tW514L5hEk5UoZsNv5iuj5NM1Wiovb5lmuY845RFnBI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=1fs25dyW3xLIBBhxXao4Izy35sLuzQoQifUh9Gk8kYN98rzV9wPQRFgya3v6F+g2s tdkgj5m8taSgjxTailT0FGCt73QgU78jrCkG2YWHWa9l7H6SxPeXBND6BvhZHiCG8I srBDD75mvSRFDPlMiyI8K6+LdWZFffuGsRaewjaU= Date: Thu, 6 Apr 2023 16:38:22 -0700 From: Andrew Morton To: "T.J. Mercier" Cc: John Stultz , jaewon31.kim@samsung.com, "sumit.semwal@linaro.org" , "daniel.vetter@ffwll.ch" , "hannes@cmpxchg.org" , "mhocko@kernel.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , "jaewon31.kim@gmail.com" Subject: Re: [PATCH v2] dma-buf/heaps: system_heap: Avoid DoS by limiting single allocations to half of all memory Message-Id: <20230406163822.faae6a90b3aa4942df6e7442@linux-foundation.org> In-Reply-To: References: <20230405185650.239f9721f066aa480e83d543@linux-foundation.org> <20230405172524.e25b62e1c548a95564b1d324@linux-foundation.org> <20230406000854.25764-1-jaewon31.kim@samsung.com> <20230406014419epcms1p3f285b6e3fdbb1457db1bcbaab9e863be@epcms1p3> <20230406021712epcms1p216f274040d25d18380668ffbfa809c48@epcms1p2> <20230405200923.9b0dca2165ef3335a0f6b112@linux-foundation.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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, 6 Apr 2023 16:27:28 -0700 "T.J. Mercier" wrote: > > When you say "decide what's the largest reasonable size", I think it > > is difficult as with the variety of RAM sizes and buffer sizes I don't > > think there's a fixed limit. Systems with more ram will use larger > > buffers for image/video capture buffers. And yes, you're right that > > ram/2-1 in a single allocation is just as broken, but I'm not sure how > > to establish a better guard rail. > > > > thanks > > -john > > I like ENOMEM with the len / PAGE_SIZE > totalram_pages() check and > WARN_ON. We know for sure that's an invalid request, and it's pretty > cheap to check as opposed to trying a bunch of reclaim before failing. Well, if some buggy caller has gone and requested eleventy bigabytes of memory, doing a lot of reclaiming before failing isn't really a problem - we don't want to optimize for this case! > For buffers smaller than that I agree with John in that I'm not sure > there's a definitive threshold. Well... why do we want to do _anything_ here? Why cater for buggy callers? I think it's because "dma-buf behaves really badly with very large allocation requests". Again, can we fix that instead?