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=-13.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,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 617F4C433E0 for ; Wed, 23 Dec 2020 01:35:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AD97522571 for ; Wed, 23 Dec 2020 01:35:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD97522571 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A26C18D0005; Tue, 22 Dec 2020 20:35:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D5818D0001; Tue, 22 Dec 2020 20:35:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C4EA8D0005; Tue, 22 Dec 2020 20:35:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0004.hostedemail.com [216.40.44.4]) by kanga.kvack.org (Postfix) with ESMTP id 761088D0001 for ; Tue, 22 Dec 2020 20:35:36 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 389A3180AD822 for ; Wed, 23 Dec 2020 01:35:36 +0000 (UTC) X-FDA: 77622829872.04.pies67_061228a27464 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id 1A516800843B for ; Wed, 23 Dec 2020 01:35:36 +0000 (UTC) X-HE-Tag: pies67_061228a27464 X-Filterd-Recvd-Size: 3477 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf14.hostedemail.com (Postfix) with ESMTP for ; Wed, 23 Dec 2020 01:35:35 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 74B432253D; Wed, 23 Dec 2020 01:35:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1608687334; bh=E2/QufhUm5QbmYYkwMorAN26mVOwdusNezXD+EAiCGE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=186twYlo93vGO50+xqZTCkfaB/dX2+7v+d92AN2wFsjVS8riTovtFkjJnMgPrqrjZ 3ZfzsfU5hKw/vVM+Y9a459VBhSWC3jdGogKAF+SSxK0QbgaPYaTtMDSf7bz2pPIrvj 0jCuFeanGFCE8O3q8qjosQvOyINhV7KNgXBP7FLg= Date: Tue, 22 Dec 2020 17:35:33 -0800 From: Andrew Morton To: Randy Dunlap Cc: linux-kernel@vger.kernel.org, Jens Axboe , Toralf =?ISO-8859-1?Q?F=F6rster?= , linux-mm@kvack.org Subject: Re: [RFC PATCH 2/2] mm: readahead: handle LARGE input to get_init_ra_size() Message-Id: <20201222173533.c9e28416835d7487b0e28cda@linux-foundation.org> In-Reply-To: <20201220211051.1416-1-rdunlap@infradead.org> References: <20201220211051.1416-1-rdunlap@infradead.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 Sun, 20 Dec 2020 13:10:51 -0800 Randy Dunlap wrote: > Add a test to detect if the input ra request size has its high order > bit set (is negative when tested as a signed long). This would be a > really Huge readahead. > > If so, WARN() with the value and a stack trace so that we can see > where this is happening and then make further corrections later. > Then adjust the size value so that it is not so Huge (although > this may not be needed). What motivates this change? Is there any reason to think this can happen? Also, everything in there *should* be unsigned, because a negative readahead is semantically nonsensical. Is our handling of this inherently unsigned quantity incorrect somewhere? > --- linux-5.10.1.orig/mm/readahead.c > +++ linux-5.10.1/mm/readahead.c > > ... > > @@ -303,14 +304,21 @@ void force_page_cache_ra(struct readahea > } > > /* > - * Set the initial window size, round to next power of 2 and square > + * Set the initial window size, round to next power of 2 > * for small size, x 4 for medium, and x 2 for large > * for 128k (32 page) max ra > * 1-8 page = 32k initial, > 8 page = 128k initial > */ > static unsigned long get_init_ra_size(unsigned long size, unsigned long max) > { > - unsigned long newsize = roundup_pow_of_two(size); > + unsigned long newsize; > + > + if ((signed long)size < 0) { /* high bit is set: ultra-large ra req */ > + WARN_ONCE(1, "%s: size=0x%lx\n", __func__, size); > + size = -size; /* really only need to flip the high/sign bit */ > + } > + > + newsize = roundup_pow_of_two(size); Is there any way in which userspace can deliberately trigger warning? Via sys_readadhead() or procfs tuning or whatever? I guess that permitting a user-triggerable WARN_ONCE() isn't a huuuuge problem - it isn't a DoS if it only triggers a single time. It does permit the malicious user to disable future valid warnings, but I don't see what incentive there would be for this. But still, it seems desirable to avoid it.