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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 699F6C3815B for ; Mon, 20 Apr 2020 08:11:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 37851218AC for ; Mon, 20 Apr 2020 08:11:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587370298; bh=z7HimAurwDR3lrdQ6oem6FxF/SwH+vDNz6rygcWxpxQ=; h=From:To:Cc:Subject:Date:List-ID:From; b=bD0PWR8Af4E5HJopMJCu854hO9wwuUVoe5NoSq3M1+alSHHXmZ84j8myXfGn/emoj XcR6MeL1GGfulHLM+Uc4eOnCByribxWcFB5FtqF5rbXnxfTzDep5O7iH6B1lFHYsd/ YOLpOr8RSolgbazZy8o1uRvM8/4Gz3K1jAzvwY0Q= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725865AbgDTILh (ORCPT ); Mon, 20 Apr 2020 04:11:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:47174 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725773AbgDTILh (ORCPT ); Mon, 20 Apr 2020 04:11:37 -0400 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2D3E320A8B; Mon, 20 Apr 2020 08:11:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587370297; bh=z7HimAurwDR3lrdQ6oem6FxF/SwH+vDNz6rygcWxpxQ=; h=From:To:Cc:Subject:Date:From; b=fqeCK0wgi2aU5Kupe7LuDEmWEQPXPlbM26SWTyXAt61zJnlCOF7Q6QvovjM95cVYa CllOGZycz/aXP3lwbWBwQ/yCTnl1PtSFfZlIKLhmiGoKgHUgGNiDh5Ya+UprL1JM8N 3DRgCuWkDnCvcu+M76vMzB0Mg0Bil/nxRq2UtVz8= From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-acpi@vger.kernel.org, sudeep.holla@arm.com, guohanjun@huawei.com, lorenzo.pieralisi@arm.com, Ard Biesheuvel Subject: [PATCH] acpi: arm64/iort: Ensure DMA mask does not exceed device limit Date: Mon, 20 Apr 2020 10:11:31 +0200 Message-Id: <20200420081131.16822-1-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org When calculating the DMA mask from the address limit provided by the firmware, we add one to the ilog2() of the end address, and pass the result to DMA_BIT_MASK(). For an end address that is not a power-of-2 minus 1, this will result in the mask to be wider than the limit, and cover memory that is not addressable by the device. Instead, we should add 1 to 'end' before taking the log, so that a limit of, say, 0x3fffffff gets translated to a mask of 30, but any value below it gets translated to 29. Signed-off-by: Ard Biesheuvel --- drivers/acpi/arm64/iort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 7d04424189df..aab2f51eff14 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -1162,7 +1162,7 @@ void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size) * firmware. */ end = dmaaddr + size - 1; - mask = DMA_BIT_MASK(ilog2(end) + 1); + mask = DMA_BIT_MASK(ilog2(end + 1)); dev->bus_dma_limit = end; dev->coherent_dma_mask = mask; *dev->dma_mask = mask; -- 2.17.1 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=-10.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT 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 D397FC3A5A0 for ; Mon, 20 Apr 2020 08:11:44 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 682CE221F4 for ; Mon, 20 Apr 2020 08:11:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HYHiat8f"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="fqeCK0wg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 682CE221F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=laKD7oEbOn8Mio7RoEv1edXy476Ztsf4v7ZLtJdqZCw=; b=HYH iat8fiH5+OB9f7GuW3erIPNyndDVQYkl3yxscGHiO1Ll9NqOiquB6yWVcKFK2ChOwoOeApGq/Uywy /6fBAW6EL/XBC4aW9A0UAZw9dd8++K+Dfn96W4srwFrQbqOlfVmxgtyCUAyD+JQrULnWpobcZjfop Hh9p4MUJRQiQ5M2utjJmKF5R+ur6HZ26kAlfdXCZZgqq01JSCzJb86paV6fiUXvx+osVJFkX0jyby ByeW913PhZFpGcsZkC4p4Ko3Uk6JC5MnycPSHmx0WxSkIcp4EhYemzdIiw/NpRQCLYHesNwE6Ax5t C3jyoa+bKxQ2PBrJcq6DCvkFqc5UP9Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQRWl-0007mw-Sm; Mon, 20 Apr 2020 08:11:39 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jQRWj-0007mb-U4 for linux-arm-kernel@lists.infradead.org; Mon, 20 Apr 2020 08:11:39 +0000 Received: from e123331-lin.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2D3E320A8B; Mon, 20 Apr 2020 08:11:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587370297; bh=z7HimAurwDR3lrdQ6oem6FxF/SwH+vDNz6rygcWxpxQ=; h=From:To:Cc:Subject:Date:From; b=fqeCK0wgi2aU5Kupe7LuDEmWEQPXPlbM26SWTyXAt61zJnlCOF7Q6QvovjM95cVYa CllOGZycz/aXP3lwbWBwQ/yCTnl1PtSFfZlIKLhmiGoKgHUgGNiDh5Ya+UprL1JM8N 3DRgCuWkDnCvcu+M76vMzB0Mg0Bil/nxRq2UtVz8= From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] acpi: arm64/iort: Ensure DMA mask does not exceed device limit Date: Mon, 20 Apr 2020 10:11:31 +0200 Message-Id: <20200420081131.16822-1-ardb@kernel.org> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200420_011137_993854_A587CFB6 X-CRM114-Status: GOOD ( 13.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel , linux-acpi@vger.kernel.org, guohanjun@huawei.com, lorenzo.pieralisi@arm.com, sudeep.holla@arm.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org When calculating the DMA mask from the address limit provided by the firmware, we add one to the ilog2() of the end address, and pass the result to DMA_BIT_MASK(). For an end address that is not a power-of-2 minus 1, this will result in the mask to be wider than the limit, and cover memory that is not addressable by the device. Instead, we should add 1 to 'end' before taking the log, so that a limit of, say, 0x3fffffff gets translated to a mask of 30, but any value below it gets translated to 29. Signed-off-by: Ard Biesheuvel --- drivers/acpi/arm64/iort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 7d04424189df..aab2f51eff14 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -1162,7 +1162,7 @@ void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size) * firmware. */ end = dmaaddr + size - 1; - mask = DMA_BIT_MASK(ilog2(end) + 1); + mask = DMA_BIT_MASK(ilog2(end + 1)); dev->bus_dma_limit = end; dev->coherent_dma_mask = mask; *dev->dma_mask = mask; -- 2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel