From patchwork Wed Mar 15 11:31:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A . Shutemov" X-Patchwork-Id: 13175677 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FF08C7618A for ; Wed, 15 Mar 2023 11:31:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17BE46B0088; Wed, 15 Mar 2023 07:31:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 08D556B008A; Wed, 15 Mar 2023 07:31:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6CB26B0089; Wed, 15 Mar 2023 07:31:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C83916B0083 for ; Wed, 15 Mar 2023 07:31:51 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 74C8016106D for ; Wed, 15 Mar 2023 11:31:51 +0000 (UTC) X-FDA: 80570918022.21.A39B799 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf15.hostedemail.com (Postfix) with ESMTP id 4D6E5A0003 for ; Wed, 15 Mar 2023 11:31:49 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=mR+gXBP7; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf15.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.65) smtp.mailfrom=kirill.shutemov@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678879909; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PbeII/iXoJsPjptKNiOA/dG/Ar/LiN8R6+pedl24yA8=; b=BEXSrZe9TzxEo2Np/kAAnUziXiqo1IxPaWnDLdFpMWzT+zFnOFGzOI+GkDy2yf3fBFNE7N mYVEjR8P05Ayv2D3dXn8A8Xal9GMoujdw2g7QAdZP5xsK6HZo9gIy3oQNMK6SZcyN8mjgW 6/OnRkYhuzqGSZcvMehmhv2zWDRhOrA= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=mR+gXBP7; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf15.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.65) smtp.mailfrom=kirill.shutemov@linux.intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678879909; a=rsa-sha256; cv=none; b=YsuCZScxAypq/e4JphBbz106L8djgPxjWKXaXv31HHQhYMP8COIirqPkUb9Lp8vIS5f2oa 25IEwaE9Fem5b+rJgTg7VgEB2/lfKRnWvcb2Xw5DurcSWHuJvzRmNahQ0MvEL+7n+7ydee Sb522ljWNNqMl9bI2a7I4KANEPotSp4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1678879909; x=1710415909; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wxXpVFa3aHUh2uZGVGV6zRauliwfaR2PzVjPmjMqjVA=; b=mR+gXBP7GxMRaVckLggVNOcKZcjy+Ymd7NtHmAIq2hapG5ps3JDbm6ne Wbnf6HnlCxM5cKveKpzgHUrJBW8XWks+Vgg1/tGzVcg+J/emYWIiXnx+h 075HjpXDmOURtqwQ9UkmVXKFUPFTzqAUjcJ6hmoqVOMWH+mITtr22vXlk Uea0LdmCD8zoS0kNdXdMQxN92/OU8NJTPZ9jGRjBKyeUQrHxkYGZcT7dw p+B/TIKIeIEQ7UcHznZrlk5c8GD8OgIfV9XyZez3YVP/AoZXqmO7rMVun 6epjE1KyQwdtBsat/flfbD/uzUchoMVr+ddvZ3FXeM/8cGod2UVy6ys90 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="340040136" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="340040136" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 04:31:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10649"; a="768456013" X-IronPort-AV: E=Sophos;i="5.98,262,1673942400"; d="scan'208";a="768456013" Received: from nopopovi-mobl1.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.33.48]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Mar 2023 04:31:43 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id ED58B10D690; Wed, 15 Mar 2023 14:31:35 +0300 (+03) From: "Kirill A. Shutemov" To: Andrew Morton , Mel Gorman , Vlastimil Babka , David Hildenbrand Cc: linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" , Robin Murphy , Jacob Pan Subject: [PATCH 09/10] iommu: Fix MAX_ORDER usage in __iommu_dma_alloc_pages() Date: Wed, 15 Mar 2023 14:31:32 +0300 Message-Id: <20230315113133.11326-10-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 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-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yexI/bGMpoaJ3DqkSJQys3i8+WV8zJ/NldOStEiMJVzfJzzNX8Rvoe1KdMqQQiwky/8tLEG6QraCtpBVdZAMlYbA+dRv1Ptybhi2U+SWLJvItuRsbMfRs3PHS+tV9MBHraq38HqhfNzznXY9tk6P8lyETGH6mEPZeK7a1ZAksErQ87qvJyCn4muPFEp8Qf6ZFY5CM2jHgXwDe2A8ckNeS2sR27iJEFQRWLbTLxLsMlQHusEeciBOjVAdp3R8So3iY9HOTPRZyqylM= 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: MAX_ORDER is not inclusive: the maximum allocation order buddy allocator can deliver is MAX_ORDER-1. Fix MAX_ORDER usage in __iommu_dma_alloc_pages(). Also use GENMASK() instead of hard to read "(2U << order) - 1" magic. Signed-off-by: Kirill A. Shutemov Cc: Robin Murphy Cc: Jacob Pan Acked-by: Robin Murphy Reviewed-by: Jacob Pan Reviewed-by: Vlastimil Babka Acked-by: Joerg Roedel --- drivers/iommu/dma-iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 99b2646cb5c7..ac996fd6bd9c 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -736,7 +736,7 @@ static struct page **__iommu_dma_alloc_pages(struct device *dev, struct page **pages; unsigned int i = 0, nid = dev_to_node(dev); - order_mask &= (2U << MAX_ORDER) - 1; + order_mask &= GENMASK(MAX_ORDER - 1, 0); if (!order_mask) return NULL; @@ -756,7 +756,7 @@ static struct page **__iommu_dma_alloc_pages(struct device *dev, * than a necessity, hence using __GFP_NORETRY until * falling back to minimum-order allocations. */ - for (order_mask &= (2U << __fls(count)) - 1; + for (order_mask &= GENMASK(__fls(count), 0); order_mask; order_mask &= ~order_size) { unsigned int order = __fls(order_mask); gfp_t alloc_flags = gfp;