Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1145161pxv; Fri, 9 Jul 2021 19:26:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBPIbC8yDDBjRnOWospt5R4Tg9ea8PP+/s0OkQ1+eCv9qstE5YNrdIBDOanHn1Ma5OWKfM X-Received: by 2002:a05:6402:14d4:: with SMTP id f20mr4333540edx.316.1625884013010; Fri, 09 Jul 2021 19:26:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625884013; cv=none; d=google.com; s=arc-20160816; b=v3RKdqk7Jf4+SkGuA6Aestmso2OPItTuLzUJc39sMhnHYAyFct5chHnZOx/vxneooK ZiXIngzCOiHz7XgfjHG+zHGWKQD23QOw5HzvVyXNh9UpjE3rAltE7q0S5VwKQgesNE8P J9SFRpy3eKlC1+fMaY+koha/LpIBtMi5DYXWpdbjYM2xCawtJAK9nC9cIccPyISCAsS2 jHAuMnsjWoV377mZ+fHgHlLns0DRMCEDqNRJdk2ZEqJseZP/OtkdxQRvt+GKFJCzHfUR qBTsz7Hx5BXpE/ogGQl/MVFFNKwLGBy/L9PkGnYYVpmBFhROO28/w1yAfuGU8bRmV8ik tY4A== 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=McFE8sGMz4h7ELCeVtNcmBDnV+G3QDNm212fiO66A5c=; b=ddRNRsYwQaD9NAiaxixpOf2eKa3KYJ9dCz9fhOx7oED05JlQ8i0ND2t60Yu1X68Meo qxjmD0neqGZKkq22cN0B8EKahsy9NZg3OSUqgNCTR9UabA7StAluA4tp++fV4ylHNOew 08bDHRqYgy/qSJhuC4iwpMzWtClU1f032/yqp/LaxBzb32HKUuit5SE2kJjdZ68aFsoA C3PqAaOIyW97+sSc1w1dlvf5shwDnU4p7uJGo7kRnAvZFRGq+kW5mqiSEtCZ9HToeDlj maUerkfWhyyDwjsOm+5UJFbpQJri8FM/gTozNPw/oGPUD2oSfwdJaZGgOCnp6nT1WW0m +Dwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JvI+2p7p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hw7si9520993ejc.83.2021.07.09.19.26.30; Fri, 09 Jul 2021 19:26:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JvI+2p7p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233747AbhGJC1w (ORCPT + 99 others); Fri, 9 Jul 2021 22:27:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:43262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233360AbhGJC0f (ORCPT ); Fri, 9 Jul 2021 22:26:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A46D6613FE; Sat, 10 Jul 2021 02:23:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625883826; bh=YjDbZylTrxVoViU6jlMBklcY7OYNE36O/b0sSEiE9e0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JvI+2p7pCPQyuZELXSf+81wlEo30FrNiFupzs8ssdzf0sMXpntPflN8mGjXcnMuXc blKhx+k9jdTgqV5Qj+YrFJbVoe1e9Qd4BHjO+o0s8jrAGd60MgLiDODxIudCtwgTZo R4m6oLxBVLO8JUEmlKo7v3zkV3GDW/FY3vn7qrQ5GaEWvqQS5/C3Pv0KbZZ47Mini+ IHZS/VRD7SvDHkpRy2llFCeJ18siIqnRjuiQF43njmrhII0+EkEudtKUB/QSP8BMJl CEHo9cmRIKhAZfm5hrOEGwdfht+IkkCKdWI7+o8W+zudCdrYySKKAyBKIfzwQUhge0 UrvzzL9GykGlQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ohad Sharabi , Oded Gabbay , Sasha Levin Subject: [PATCH AUTOSEL 5.12 074/104] habanalabs: fix mask to obtain page offset Date: Fri, 9 Jul 2021 22:21:26 -0400 Message-Id: <20210710022156.3168825-74-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210710022156.3168825-1-sashal@kernel.org> References: <20210710022156.3168825-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ohad Sharabi [ Upstream commit 0f37510ca34848718db1003479bb4671e8f3c112 ] When converting virtual address to physical we need to add correct offset to the physical page. For this we need to use mask that include ALL bits of page offset. Signed-off-by: Ohad Sharabi Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay Signed-off-by: Sasha Levin --- drivers/misc/habanalabs/common/mmu/mmu.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/misc/habanalabs/common/mmu/mmu.c b/drivers/misc/habanalabs/common/mmu/mmu.c index 93c9e5f587e1..86dfa7c41ee7 100644 --- a/drivers/misc/habanalabs/common/mmu/mmu.c +++ b/drivers/misc/habanalabs/common/mmu/mmu.c @@ -501,12 +501,20 @@ static void hl_mmu_pa_page_with_offset(struct hl_ctx *ctx, u64 virt_addr, if ((hops->range_type == HL_VA_RANGE_TYPE_DRAM) && !is_power_of_2(prop->dram_page_size)) { - u32 bit; + unsigned long dram_page_size = prop->dram_page_size; u64 page_offset_mask; u64 phys_addr_mask; + u32 bit; - bit = __ffs64((u64)prop->dram_page_size); - page_offset_mask = ((1ull << bit) - 1); + /* + * find last set bit in page_size to cover all bits of page + * offset. note that 1 has to be added to bit index. + * note that the internal ulong variable is used to avoid + * alignment issue. + */ + bit = find_last_bit(&dram_page_size, + sizeof(dram_page_size) * BITS_PER_BYTE) + 1; + page_offset_mask = (BIT_ULL(bit) - 1); phys_addr_mask = ~page_offset_mask; *phys_addr = (tmp_phys_addr & phys_addr_mask) | (virt_addr & page_offset_mask); -- 2.30.2