From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F52FC433E0 for ; Mon, 1 Feb 2021 13:52:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6447064D9D for ; Mon, 1 Feb 2021 13:52:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6447064D9D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C9D076B0074; Mon, 1 Feb 2021 08:52:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C4D0E6B0080; Mon, 1 Feb 2021 08:52:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3C186B0081; Mon, 1 Feb 2021 08:52:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9D20B6B0074 for ; Mon, 1 Feb 2021 08:52:11 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 51B5B3632 for ; Mon, 1 Feb 2021 13:52:11 +0000 (UTC) X-FDA: 77769838062.11.hole02_1f10da0275c2 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 24E74180F8B8B for ; Mon, 1 Feb 2021 13:52:11 +0000 (UTC) X-HE-Tag: hole02_1f10da0275c2 X-Filterd-Recvd-Size: 3928 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Mon, 1 Feb 2021 13:52:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=BN+83di4PakIqTIRk9uaDMO/1Mfo2bgjpgiaTqZbVFE=; b=s9UqflYCs9PwSthJBYTPSbIRA2 MnAfMnfxTEH0ibqQ7IHjphOsmqpGeEcs78d5b8BceTrtKGYNtiSWO9bKZ/lHUZbTJp+BVmRaR5EOq Vj9NvIo8MtnNBIbeQh2tCmf3CMcdQ+2OOvx1lQw6bohcy0+JV7UYuXi3D43C6d+wYH7Kas1pj7Cfq +6ONH/eUVUgNapFUimgSyWlcgob0Mbhsl3p5U9Fnmlc+utTjkAoCXk6gZkdBjQy7OeFbgjLBqpts2 Kws4F1QwAmRQF+Pan4FMtT0vOzfPenPqh0TEDys53Rf2w5m+qbnBKydRrjOZovvOyqI1jU0zOv+yb MduQhJGw==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1l6Zcc-00DqGY-1T; Mon, 01 Feb 2021 13:52:06 +0000 Date: Mon, 1 Feb 2021 13:52:06 +0000 From: Matthew Wilcox To: Vlastimil Babka Cc: Steven Noonan , "linux-mm@kvack.org" , Christoph Hellwig , Josef Bacik Subject: Re: "cat /proc/sys/kernel/random/entropy_avail" sometimes causes page allocation failure Message-ID: <20210201135206.GQ308988@casper.infradead.org> References: <592ccd73-9152-0748-a7ce-be663593f8da@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <592ccd73-9152-0748-a7ce-be663593f8da@suse.cz> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Feb 01, 2021 at 01:20:04PM +0100, Vlastimil Babka wrote: > On 2/1/21 12:26 PM, Steven Noonan wrote: > > (Please CC me on replies, I'm not subscribed to the list.) > > > > I started seeing this problem several months ago, but after some Google searches I concluded that someone had already root caused and fixed it, and I just needed to wait for a newer kernel to come along: > > > > https://www.spinics.net/lists/linux-mm/msg226311.html > > Yeah, that thread mentions Josef's series [1], but I don't see that it made it > into git log. What happened to it? Meanwhile Matthew refactored it with > "4bd6a7353ee1 ("sysctl: Convert to iter interfaces")" which left the kzalloc() > but changed count to count+1, which would explain the change from order-5 to > order-6. In my quick test, strace cat tells me it uses 128k sized read, which is > order-5. > > So miminally there should be kvzalloc(), but it's still somewhat unfortunate to > do that for reading a few bytes. > Also the check for KMALLOC_MAX_SIZE happens before the +1. Meh. Matthew? That's why the check is >= KMALLOC_MAX_SIZE. Switching to kvzalloc() means we'll only allocate one extra page, not twice as many pages. We can't know how large the proc file is going to want the buffer to be, but perhaps we can do this ... @@ -569,17 +569,16 @@ static ssize_t proc_sys_call_handler(struct kiocb *iocb, struct iov_iter *iter, /* don't even try if the size is too large */ error = -ENOMEM; - if (count >= KMALLOC_MAX_SIZE) + if (count > KMALLOC_MAX_SIZE) goto out; - kbuf = kzalloc(count + 1, GFP_KERNEL); + kbuf = kvzalloc(count, GFP_KERNEL); if (!kbuf) goto out; if (write) { error = -EFAULT; - if (!copy_from_iter_full(kbuf, count, iter)) + if (!copy_from_iter_full(kbuf, count - 1, iter)) goto out_free_buf; - kbuf[count] = '\0'; } error = BPF_CGROUP_RUN_PROG_SYSCTL(head, table, write, &kbuf, &count,