public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "David Gow" <davidgow@google.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Maíra Canal" <mcanal@igalia.com>,
	"Arunpravin Paneer Selvam" <arunpravin.paneerselvam@amd.com>,
	"Sasha Levin" <sashal@kernel.org>,
	airlied@gmail.com, daniel@ffwll.ch, mairacanal@riseup.net,
	javierm@redhat.com, djwong@kernel.org, arthurgrillo@riseup.net,
	Jason@zx2c4.com, dri-devel@lists.freedesktop.org
Subject: [PATCH AUTOSEL 6.1 12/17] drm: test: Fix 32-bit issue in drm_buddy_test
Date: Thu,  6 Apr 2023 07:32:06 -0400	[thread overview]
Message-ID: <20230406113211.648424-12-sashal@kernel.org> (raw)
In-Reply-To: <20230406113211.648424-1-sashal@kernel.org>

From: David Gow <davidgow@google.com>

[ Upstream commit 25bbe844ef5c4fb4d7d8dcaa0080f922b7cd3a16 ]

The drm_buddy_test KUnit tests verify that returned blocks have sizes
which are powers of two using is_power_of_2(). However, is_power_of_2()
operations on a 'long', but the block size is a u64. So on systems where
long is 32-bit, this can sometimes fail even on correctly sized blocks.

This only reproduces randomly, as the parameters passed to the buddy
allocator in this test are random. The seed 0xb2e06022 reproduced it
fine here.

For now, just hardcode an is_power_of_2() implementation using
x & (x - 1).

Signed-off-by: David Gow <davidgow@google.com>
Acked-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Maíra Canal <mcanal@igalia.com>
Reviewed-by: Arunpravin Paneer Selvam <arunpravin.paneerselvam@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230329065532.2122295-2-davidgow@google.com
Signed-off-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/gpu/drm/tests/drm_buddy_test.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/tests/drm_buddy_test.c b/drivers/gpu/drm/tests/drm_buddy_test.c
index 62f69589a72d3..a699fc0dc8579 100644
--- a/drivers/gpu/drm/tests/drm_buddy_test.c
+++ b/drivers/gpu/drm/tests/drm_buddy_test.c
@@ -89,7 +89,8 @@ static int check_block(struct kunit *test, struct drm_buddy *mm,
 		err = -EINVAL;
 	}
 
-	if (!is_power_of_2(block_size)) {
+	/* We can't use is_power_of_2() for a u64 on 32-bit systems. */
+	if (block_size & (block_size - 1)) {
 		kunit_err(test, "block size not power of two\n");
 		err = -EINVAL;
 	}
-- 
2.39.2


  parent reply	other threads:[~2023-04-06 11:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-06 11:31 [PATCH AUTOSEL 6.1 01/17] f2fs: Fix f2fs_truncate_partial_nodes ftrace event Sasha Levin
2023-04-06 11:31 ` [PATCH AUTOSEL 6.1 02/17] platform/x86/intel: vsec: Fix a memory leak in intel_vsec_add_aux Sasha Levin
2023-04-06 11:31 ` [PATCH AUTOSEL 6.1 03/17] platform/x86 (gigabyte-wmi): Add support for A320M-S2H V2 Sasha Levin
2023-04-06 11:31 ` [PATCH AUTOSEL 6.1 04/17] selftests: sigaltstack: fix -Wuninitialized Sasha Levin
2023-04-06 11:31 ` [PATCH AUTOSEL 6.1 05/17] scsi: megaraid_sas: Fix fw_crash_buffer_show() Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 06/17] scsi: core: Improve scsi_vpd_inquiry() checks Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 07/17] net: dsa: b53: mmap: add phy ops Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 08/17] platform/x86: gigabyte-wmi: add support for B650 AORUS ELITE AX Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 09/17] s390/ptrace: fix PTRACE_GET_LAST_BREAK error handling Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 10/17] nvme-pci: mark Lexar NM760 as IGNORE_DEV_SUBNQN Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 11/17] drm: buddy_allocator: Fix buddy allocator init on 32-bit systems Sasha Levin
2023-04-06 11:32 ` Sasha Levin [this message]
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 13/17] nvme-tcp: fix a possible UAF when failing to allocate an io queue Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 14/17] xen/netback: use same error messages for same errors Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 15/17] platform/x86: gigabyte-wmi: add support for X570S AORUS ELITE Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 16/17] platform/x86: asus-nb-wmi: Add quirk_asus_tablet_mode to other ROG Flow X13 models Sasha Levin
2023-04-06 11:32 ` [PATCH AUTOSEL 6.1 17/17] mtd: spi-nor: fix memory leak when using debugfs_lookup() Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230406113211.648424-12-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=airlied@gmail.com \
    --cc=arthurgrillo@riseup.net \
    --cc=arunpravin.paneerselvam@amd.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=davidgow@google.com \
    --cc=djwong@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=javierm@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mairacanal@riseup.net \
    --cc=mcanal@igalia.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox