Message ID | 20230315113133.11326-4-kirill.shutemov@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2273114wrd; Wed, 15 Mar 2023 04:33:46 -0700 (PDT) X-Google-Smtp-Source: AK7set+Ez3nwgwPnZ9zvRDfZSjyWdLU85nRjB9ehvgumCNYrWkP+1jTA88+lBvowIzLYpcZdOhof X-Received: by 2002:a05:6830:4118:b0:68d:6a22:396c with SMTP id w24-20020a056830411800b0068d6a22396cmr22827927ott.3.1678880026280; Wed, 15 Mar 2023 04:33:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678880026; cv=none; d=google.com; s=arc-20160816; b=UYCxsywkG7y/2Z+tHatv8bPzfhAwgZvP42Y0/plcnMqw0aq5cmD5TaDAU01AFnkH18 RE+r9OY66PBbJrkaN+lMcNzqnPpGoAfmB4BUM3SaZsfuOVsH/EEaIzcxZQszfFw+lbAP rHGEaHHqgvHthpbPKztjejAlGgnehH9ODT/8JtmeDMYfnhEq/FspEw6FzCSog011Dy8t Ltb1WE4H1SNR8KQlFFpq6XFu1ZHcHvTxs31AW99E0mPOhdbP6MUeNggL43xTSk7lygE8 Dbk0lrd628whqMh/iVJ8YeFnA5HHK4PoJNoLrI71r9NipUVHfAFC4i2tegCBIWvr+TGF 2uzQ== 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:date:subject:cc:to:from :dkim-signature; bh=MD1pFyz84vdYwyMP/5a1kTCUnI97p/yuOqanyBZbHs4=; b=yyN9M4lgTxi3itDQUlnDcewDA8PV1+7tIi0C4ndfgSR2kNY5ICxtHFqZZBm53y10Tr UnYOJzJQ90GFkfRwb+Ywr9hkkvjdYqDqxB/KRiXnw4HCG6icSyOKajpVkS0UYY1W5nus cyySlzHFv8+bK8vsbh2qw+r6qSzTRfvCvVLcpvwb6xJA3a8k8qWkJAZEATtCRyhCr2P2 YtRv3Hf4WFPmIcJs6WWXWJTOQfAPm7J1JC+GWFoZBkLjknuniHU5LuD9IdAQF+tq1C/a ABi49etd3URpXHH5XPl5p1YITCZ1MbIMwf9TDuqJ6NmFb/Fhqzk0REEJXh4YX3DnEurq XcEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ElAxf5Jw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j4-20020a9d7d84000000b0068bcfb2ec21si4177528otn.185.2023.03.15.04.33.33; Wed, 15 Mar 2023 04:33:46 -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=@intel.com header.s=Intel header.b=ElAxf5Jw; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231527AbjCOLbp (ORCPT <rfc822;ruipengqi7@gmail.com> + 99 others); Wed, 15 Mar 2023 07:31:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230356AbjCOLbm (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 15 Mar 2023 07:31:42 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1937864846; Wed, 15 Mar 2023 04:31:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678879902; x=1710415902; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CbKC9In0sfgAFhGmEkzB7Bb+JmElN2MpqrLq/60tyc4=; b=ElAxf5JwDWlsUz4WnDO0m9NyEmkAV2NOUUFD8qSfgU5WNco8iswrNDK/ JxrlzVeaTH3ohGiyvpG9OqH6PnQPETgTErrS1IJTHRipzvVjqHA4xHOsW u/H3MKTPE9LFLn3n2T1ailbwqD5u7q+ecvpQ+bqdcnga9TtLOP/VbdSle Bb7G7iE5RBCnXSmP02CHBt2U1dvgbFoRwkeIWjUVKffnx1tzEe9cug62j b7Pn1tNrutSldOoKv2sOzMOfV2TpMRczu252huVVkppqOS/75UCXhcjDJ WhVjNtEfeWuHmoXcUneeQHmxR6GVBLY4p3PHXzGI9xRzdGe1zURM6iKeQ A==; X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="317330268" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="317330268" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 04:31:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="925310514" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="925310514" Received: from nopopovi-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.33.48]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 04:31:38 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id BB81D10CC9F; Wed, 15 Mar 2023 14:31:35 +0300 (+03) From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com> To: Andrew Morton <akpm@linux-foundation.org>, Mel Gorman <mgorman@suse.de>, Vlastimil Babka <vbabka@suse.cz>, David Hildenbrand <david@redhat.com> Cc: linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>, Denis Efremov <efremov@linux.com> Subject: [PATCH 03/10] floppy: Fix MAX_ORDER usage Date: Wed, 15 Mar 2023 14:31:26 +0300 Message-Id: <20230315113133.11326-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230315113133.11326-1-kirill.shutemov@linux.intel.com> References: <20230315113133.11326-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_NONE,URIBL_BLOCKED autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760433302789761688?= X-GMAIL-MSGID: =?utf-8?q?1760433302789761688?= |
Series |
Fix confusion around MAX_ORDER
|
|
Commit Message
Kirill A. Shutemov
March 15, 2023, 11:31 a.m. UTC
MAX_ORDER is not inclusive: the maximum allocation order buddy allocator
can deliver is MAX_ORDER-1.
Fix MAX_ORDER usage in floppy code.
Also allocation buffer exactly PAGE_SIZE << MAX_ORDER bytes is okay. Fix
MAX_LEN check.
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Denis Efremov <efremov@linux.com>
---
drivers/block/floppy.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On Wed, Mar 15, 2023 at 02:31:26PM +0300, Kirill A. Shutemov wrote: > MAX_ORDER is not inclusive: the maximum allocation order buddy allocator > can deliver is MAX_ORDER-1. > > Fix MAX_ORDER usage in floppy code. > > Also allocation buffer exactly PAGE_SIZE << MAX_ORDER bytes is okay. Fix > MAX_LEN check. > > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> > Cc: Denis Efremov <efremov@linux.com> Acked-by: Mike Rapoport (IBM) <rppt@kernel.org> > --- > drivers/block/floppy.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c > index 487840e3564d..90d2dfb6448e 100644 > --- a/drivers/block/floppy.c > +++ b/drivers/block/floppy.c > @@ -3079,7 +3079,7 @@ static void raw_cmd_free(struct floppy_raw_cmd **ptr) > } > } > > -#define MAX_LEN (1UL << MAX_ORDER << PAGE_SHIFT) > +#define MAX_LEN (1UL << (MAX_ORDER - 1) << PAGE_SHIFT) > > static int raw_cmd_copyin(int cmd, void __user *param, > struct floppy_raw_cmd **rcmd) > @@ -3108,7 +3108,7 @@ static int raw_cmd_copyin(int cmd, void __user *param, > ptr->resultcode = 0; > > if (ptr->flags & (FD_RAW_READ | FD_RAW_WRITE)) { > - if (ptr->length <= 0 || ptr->length >= MAX_LEN) > + if (ptr->length <= 0 || ptr->length > MAX_LEN) > return -EINVAL; > ptr->kernel_data = (char *)fd_dma_mem_alloc(ptr->length); > fallback_on_nodma_alloc(&ptr->kernel_data, ptr->length); > -- > 2.39.2 >
On 3/15/23 12:31, Kirill A. Shutemov wrote: > MAX_ORDER is not inclusive: the maximum allocation order buddy allocator > can deliver is MAX_ORDER-1. > > Fix MAX_ORDER usage in floppy code. > > Also allocation buffer exactly PAGE_SIZE << MAX_ORDER bytes is okay. Fix > MAX_LEN check. > > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Acked-by: Vlastimil Babka <vbabka@suse.cz> > Cc: Denis Efremov <efremov@linux.com> > --- > drivers/block/floppy.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c > index 487840e3564d..90d2dfb6448e 100644 > --- a/drivers/block/floppy.c > +++ b/drivers/block/floppy.c > @@ -3079,7 +3079,7 @@ static void raw_cmd_free(struct floppy_raw_cmd **ptr) > } > } > > -#define MAX_LEN (1UL << MAX_ORDER << PAGE_SHIFT) > +#define MAX_LEN (1UL << (MAX_ORDER - 1) << PAGE_SHIFT) > > static int raw_cmd_copyin(int cmd, void __user *param, > struct floppy_raw_cmd **rcmd) > @@ -3108,7 +3108,7 @@ static int raw_cmd_copyin(int cmd, void __user *param, > ptr->resultcode = 0; > > if (ptr->flags & (FD_RAW_READ | FD_RAW_WRITE)) { > - if (ptr->length <= 0 || ptr->length >= MAX_LEN) > + if (ptr->length <= 0 || ptr->length > MAX_LEN) > return -EINVAL; > ptr->kernel_data = (char *)fd_dma_mem_alloc(ptr->length); > fallback_on_nodma_alloc(&ptr->kernel_data, ptr->length);
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 487840e3564d..90d2dfb6448e 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -3079,7 +3079,7 @@ static void raw_cmd_free(struct floppy_raw_cmd **ptr) } } -#define MAX_LEN (1UL << MAX_ORDER << PAGE_SHIFT) +#define MAX_LEN (1UL << (MAX_ORDER - 1) << PAGE_SHIFT) static int raw_cmd_copyin(int cmd, void __user *param, struct floppy_raw_cmd **rcmd) @@ -3108,7 +3108,7 @@ static int raw_cmd_copyin(int cmd, void __user *param, ptr->resultcode = 0; if (ptr->flags & (FD_RAW_READ | FD_RAW_WRITE)) { - if (ptr->length <= 0 || ptr->length >= MAX_LEN) + if (ptr->length <= 0 || ptr->length > MAX_LEN) return -EINVAL; ptr->kernel_data = (char *)fd_dma_mem_alloc(ptr->length); fallback_on_nodma_alloc(&ptr->kernel_data, ptr->length);