From patchwork Fri Feb 9 16:49:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 199001 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp985329dyd; Fri, 9 Feb 2024 08:55:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+Zj0uQPbgZNxcmLAVD5l5CxQRCntnH7dAGm00kwySfynaSzuy+OojomzBHL5nJqr9DMdd X-Received: by 2002:a05:622a:1649:b0:42c:60b2:10c6 with SMTP id y9-20020a05622a164900b0042c60b210c6mr1189915qtj.35.1707497701824; Fri, 09 Feb 2024 08:55:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707497701; cv=pass; d=google.com; s=arc-20160816; b=duekhRaB/Yn0+gvbEkjfqfQI+Y7VBIzKlSjwgXx83pERF4eAKQ8pYIQ9JzLJgHQAQJ 4h8W6BRzWSCKcgZAlQvHE66Hbi9cvQI1MWbc21J2tWb5EoPuLiEdd4eK4HahoLOGjbO2 RhUCUuYAcCcAVaaxcJQR3Itl9y+9xBdKPjx2vJjvcv6ZSuzkAFlFoYAYb2BkCpy48wg0 l9p22reSqKyTIJeejgqeJmW/XWSnG3qGzh5Ho/u5kv8sFmOSrQqF4ZVmZq3gOjf6CtEW YqTG1wNPxE3urY56RiSx9W1p63ull+wutYUlpa4bPy8e3tyMe/7GGfhME0p7Pip5Nvww 0ocg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=lo5WCo84XMUZLomSoeZcC3ui5P1IgcAkfSqd59c/Ddc=; fh=Q4z5X4k8tgv+eYhvl/WX6Hro0GgxmmYqim4WPUeQo8c=; b=f5M3KoJysILiLPsmY3r6pjLHl+xyS7tRWkhsCzLmnagKERoSm6ViYA+xhhyvqPtb+o hBhAlzHlJrnBXroU0LiHQ9l5Tfq/F6/Za3ScrcxNZDLfAeVJnNoQAyRIUwJkPBEjyITS Glr1WLN8Jr3xhLAynjY+6Nnkg5tM5efl9weWwURIzL9El6Wd5H9TIQVPyZAI6YLEl216 mfo6kx14WdL2G8dtsMxz/cThxpOe72/lULP3KyILYfvjpIkhwQZrNFYjsiLLy7k1V2Se Dsytb5Nh8M98vQ/1RAIiV7SI5kjAENiAC/SpMj0DR4CvoocPMoJyk03NKvOlgM07BnxE ccEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-59673-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59673-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCUXwdm0qKe4CBpPmI8ySXI9p4RR3t9vS/Te7vibsE+k8mDlxolr7gn9F+rrgM6xKUcVAoG7p3UTREd7qR0WN8+UA7UGwA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j11-20020ac85c4b000000b0042c2e4f5c68si2255958qtj.631.2024.02.09.08.55.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 08:55:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59673-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-59673-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59673-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9831D1C20F84 for ; Fri, 9 Feb 2024 16:55:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8DF3D82874; Fri, 9 Feb 2024 16:50:31 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2C89B80BF6; Fri, 9 Feb 2024 16:50:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497429; cv=none; b=lNPfiRL9YA0mAN9VSOrb2pgvGAA9QwQUeJwfdkRSXYoiJnxhDG2COqIgacr50vaXw7a2k/rwm7rcivDB+H+gJtE2tG4e79JADmwg9KcdXE+bMuXizEuE+84OC3/CscvWifvzZn3+X+METq2cT9GNZOie9uStF3swImGYiHmfiVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497429; c=relaxed/simple; bh=78sazIr90PfD2p3pMcVPhdyFlfiEISIeaG+WW9mJPWA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K2WZeKe83pXGBZ7MtnW/o91asr+8l4CXVtnv4xMNS1VZXNKtBFIq05eiGdKHykBaFqrtaBJ0SCoMbAukssgNJ8YGXy+fK2056kOgqHxxth1ly4AZ1lhOo57QW0cXGKzjSQL+LID9+YkdX7NIW8OJfrxDP4+hBIP+MnHEP1WTtMc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A64EFFEC; Fri, 9 Feb 2024 08:51:08 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D0E8C3F64C; Fri, 9 Feb 2024 08:50:22 -0800 (PST) From: Robin Murphy To: Cc: Vineet Gupta , Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Suravee Suthikulpanit , David Woodhouse , Lu Baolu , Niklas Schnelle , Matthew Rosato , Gerald Schaefer , Jean-Philippe Brucker , Rob Herring , Frank Rowand , Marek Szyprowski , Jason Gunthorpe , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, iommu@lists.linux.dev, devicetree@vger.kernel.org, Rob Herring Subject: [PATCH v3 1/7] OF: Retire dma-ranges mask workaround Date: Fri, 9 Feb 2024 16:49:58 +0000 Message-Id: <3d759722a5bd898dc5736048b4a5f30689c33888.1707493264.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.39.2.101.g768bb238c484.dirty In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790441110020618349 X-GMAIL-MSGID: 1790441110020618349 The fixup adding 1 to the dma-ranges size may have been for the benefit of some early AMD Seattle DTs, or may have merely been a just-in-case, but either way anyone who might have deserved to get the message has hopefully seen the warning in the 9 years we've had it there. The modern dma_range_map mechanism should happily handle odd-sized ranges with no ill effect, so there's little need to care anyway now. Clean it up. Acked-by: Rob Herring Signed-off-by: Robin Murphy --- v2: Tweak commit message --- drivers/of/device.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index de89f9906375..a988bee2ee5a 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -129,22 +129,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, dma_end = r->dma_start + r->size; } size = dma_end - dma_start; - - /* - * Add a work around to treat the size as mask + 1 in case - * it is defined in DT as a mask. - */ - if (size & 1) { - dev_warn(dev, "Invalid size 0x%llx for dma-range(s)\n", - size); - size = size + 1; - } - - if (!size) { - dev_err(dev, "Adjusted size 0x%llx invalid\n", size); - kfree(map); - return -EINVAL; - } } /* From patchwork Fri Feb 9 16:49:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 199003 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp985517dyd; Fri, 9 Feb 2024 08:55:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVvQSTzVp75W3fWz+3HO+TAVcbfUQbY0v/TzihvziX79whUQWQbtEVPCZHCHY7It7fcO8ktLvxHtX1woKrx5Lvj32y7Qw== X-Google-Smtp-Source: AGHT+IG07Vgq4Fl/MF2wudeF1KIwwYBGSD3wcApfTBxc6RXqbO47CWFmC6u+snGKublILuLV3gEP X-Received: by 2002:a17:906:d97c:b0:a38:80a3:6692 with SMTP id rp28-20020a170906d97c00b00a3880a36692mr1617005ejb.30.1707497724150; Fri, 09 Feb 2024 08:55:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707497724; cv=pass; d=google.com; s=arc-20160816; b=DC+GpK7jIZ0SBp5w2ZYaxxoUj3fAwrjHvYdz6wN8zvqYt7wKvVtjCbNzNAfSiv1Yqi 7WGBFa2GLJiMeK97sYPo5mwiIiS7IbreZnyaRz/xREL5mS7s2JOkY7Buef6NLmgfRdcM ti7nhn9Jsg9QwDrgtlpJrIIgp2tftn87TgcYgApYbxXYNx5Pmig3dFCSkRI3PWmmiqMv nR0Ik6IxDvNn3ArOqr/yFYzHGZZrUJaBE4lrwA73henKuS1JgR3mxz2NCMbLns1TWvQB a7tdpowvy9DS5Hd9Gp1K7sF+rbiOu0Z3dF7z6jfcEBTXk+J4LPMJjCEq8are9AxpwwqI FP4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=pfeUXw+IXP+I3UVG2ii+itrHqgDTs/CpdRW5iE0+swg=; fh=/VBm/t2YxLowDtqQrVicaYZvuFQ4q3qypObbhlUhFr8=; b=LVyZiIVShquV2pl1eGTxzALymttlyiHxkZ5UcDzR+YZnY8VpmvGGCT9VK/ij0+9vp5 ykjzvHJruxplkyMouNsVsSIHLRTkfhpfWmhmSE1d2u8OpiFrVeLFLudN+CccjDpbYSis 03QzO7lfFxK3Jc6fjHNJi1mAJ0uHjknqGQ7tZrKWq7y5UoqwOOKlRNC7PhPBkOtqcDMf 6c9vv3OKlV8TC6S4mtvbfzLs78fF0dGBx1Caky24U29wgK7ymKG09/Su8VyPfFCiP0OI 5yQAPA5r1lKLMYMAvWyNnOLP4CT8fwD6zTPUQjJ/qYzaKLvNO5Fuk9aO7a84UqVhBQH8 hgtQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-59674-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59674-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVQ8ozjZynrBgyyr1H8XWLdkl9bncFS/nnl2jcWjWOjkFiMEdByeD68N9FgbYGP3Sf3aLmatSgOwC6UtX6l+Ql4nyWm/g== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s24-20020a170906455800b00a385cf0e6besi1027942ejq.53.2024.02.09.08.55.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 08:55:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59674-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-59674-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59674-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C31C01F21608 for ; Fri, 9 Feb 2024 16:55:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9469A80BF7; Fri, 9 Feb 2024 16:50:35 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 58C478288F; Fri, 9 Feb 2024 16:50:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497433; cv=none; b=mvVH7/VjY6p3PZSiRILX4ZBhCVyhK+SEWtnMVYbo8Dn/Kq4hpl3Ky4YwrLYmvc7gqeZ7IitHmq8xSpB0RrOPcEd91NaoXquKZJ2IyAg06D9Um3aCoS8dKw01+kuJxflSBiGUZMOESPxy2zN7FVf804Vlgg0ZIKq6wnjlEMC0Mi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497433; c=relaxed/simple; bh=pOu8SkBP1o2YI89QRW9IkEizSqtcRRWP9wRbqkcsIYk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FprqiAZ+MvoFbuav9dpLRdAPv0zJ0jGlHw0ApYnDt8BraHsZUOXE58+g4JNc8ZOzaCiG8Wex8eoZQWzEPTkWGMtC4m6qQ0CfdRbWHmSIzrJzFxVd2mdel3Kro4Yacs/Q0GDv/OUN/ceeqxGRrTqlj8eSlJuma4GsbjuaXMCC6+M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C5B9F1570; Fri, 9 Feb 2024 08:51:12 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D72AC3F7F5; Fri, 9 Feb 2024 08:50:26 -0800 (PST) From: Robin Murphy To: Cc: Vineet Gupta , Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Suravee Suthikulpanit , David Woodhouse , Lu Baolu , Niklas Schnelle , Matthew Rosato , Gerald Schaefer , Jean-Philippe Brucker , Rob Herring , Frank Rowand , Marek Szyprowski , Jason Gunthorpe , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, iommu@lists.linux.dev, devicetree@vger.kernel.org, Rob Herring , Jason Gunthorpe Subject: [PATCH v3 2/7] OF: Simplify DMA range calculations Date: Fri, 9 Feb 2024 16:49:59 +0000 Message-Id: X-Mailer: git-send-email 2.39.2.101.g768bb238c484.dirty In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790441133461677568 X-GMAIL-MSGID: 1790441133461677568 Juggling start, end, and size values for a range is somewhat redundant and a little hard to follow. Consolidate down to just using inclusive start and end, which saves us worrying about size overflows for full 64-bit ranges (note that passing a potentially-overflowed value through to arch_setup_dma_ops() is benign for all current implementations, and this is working towards removing that anyway). Acked-by: Rob Herring Reviewed-by: Jason Gunthorpe Signed-off-by: Robin Murphy --- drivers/of/device.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index a988bee2ee5a..841ccd3a19d1 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -96,7 +96,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, const struct bus_dma_region *map = NULL; struct device_node *bus_np; u64 dma_start = 0; - u64 mask, end, size = 0; + u64 mask, end = 0; bool coherent; int iommu_ret; int ret; @@ -118,17 +118,15 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, return ret == -ENODEV ? 0 : ret; } else { const struct bus_dma_region *r = map; - u64 dma_end = 0; /* Determine the overall bounds of all DMA regions */ for (dma_start = ~0; r->size; r++) { /* Take lower and upper limits */ if (r->dma_start < dma_start) dma_start = r->dma_start; - if (r->dma_start + r->size > dma_end) - dma_end = r->dma_start + r->size; + if (r->dma_start + r->size > end) + end = r->dma_start + r->size; } - size = dma_end - dma_start; } /* @@ -142,16 +140,15 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, dev->dma_mask = &dev->coherent_dma_mask; } - if (!size && dev->coherent_dma_mask) - size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1); - else if (!size) - size = 1ULL << 32; + if (!end && dev->coherent_dma_mask) + end = dev->coherent_dma_mask; + else if (!end) + end = (1ULL << 32) - 1; /* * Limit coherent and dma mask based on size and default mask * set by the driver. */ - end = dma_start + size - 1; mask = DMA_BIT_MASK(ilog2(end) + 1); dev->coherent_dma_mask &= mask; *dev->dma_mask &= mask; @@ -185,7 +182,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, } else dev_dbg(dev, "device is behind an iommu\n"); - arch_setup_dma_ops(dev, dma_start, size, coherent); + arch_setup_dma_ops(dev, dma_start, end - dma_start + 1, coherent); if (iommu_ret) of_dma_set_restricted_buffer(dev, np); From patchwork Fri Feb 9 16:50:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 199016 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp990707dyd; Fri, 9 Feb 2024 09:02:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IEloy3dXrn+LCsc+a6AXve6/7tfo69Qpr0EKTHKEozbkN20OtvT/YRO8s/a60YvtoHpMsg8 X-Received: by 2002:a05:6a20:e68c:b0:19e:8b31:f1ae with SMTP id mz12-20020a056a20e68c00b0019e8b31f1aemr2755083pzb.29.1707498178106; Fri, 09 Feb 2024 09:02:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707498178; cv=pass; d=google.com; s=arc-20160816; b=RI9ya2XvJJQj+y3FV1udZ2KXXjBuXPzeGnrazkMW+c7sOZN4AngUQo+GReTzG/R9JB KiHWJ5GhezJlWmyLamp//w33Gf3lr1AJX5D8vHpAMyQssHGmxwgtmCmhA3r4eQ3VY0/W uTB1z1UIS01D1b53rfgQWwXSBQ18K6VyAhWGMDCpGH3kYxfb2/5TTcIK0NR3utMYSIy9 QFZBKG++Vpf1m2xLipPrLtqFwKgSF00NNTBH+67gYJo3IKixNea9RoGlR9KPj23Ch6B1 XtvBgrr9jWYL2o8d5b23+EVu+G5tVuCyWZhYgZqp6R/+stPpitE7K+ZTBWwhS5ia91op uM5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=WyE5M/CZJ41J/09Fgq0ZBT6V6pAfOZMZWcgdqKVZxNM=; fh=XCyJ/vTV7zyl7w1Dbl1WzFVrWaeDCrKZIBF7Oo1ic4I=; b=Bkgy4A8it2PhtsCJTHNDv9PE3Jhv4le+PwvaqB6RcHjAN8Zw3jMbMO+1oepm6Xgkr5 lCLQC8rPEzUQaFUrzMGahzQk4m9ccIey9WGPBaB7PQsJp50igJVVkF1X0U366Hw4yu3b CcBUiYAr7/tlegWGW9CrCF/gnYoXmdPWL3UbpYkzwy56ArDFd7C3iIT6pkhnvnbtdKqL f1xspHkyS0ekDzwwrbl3TlsWKES0HC2UyCMpO7Cc1WgE4k5SXhR8P1tFXX/YM1M5V1Lr NPonKO5do77ybYGbU3QYjeoFuUzCLazwu66Id3AzjM9QFcHHLglytsT4BDQvjKBoM/lv oung==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-59675-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59675-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCW1xsIc9XJT2Dz8xzCCaCRSBOPnsTxwpQp2JguN2qoLYZd5mdmvc7zlTwN9jdY3qyUPCKTurJ7316A3yZonQvBzyVaFVA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l12-20020a65680c000000b005dbd0ff2e5dsi2002456pgt.811.2024.02.09.09.02.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 09:02:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59675-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-59675-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59675-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 20B9B28EE0D for ; Fri, 9 Feb 2024 16:55:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B5EEC12BE8A; Fri, 9 Feb 2024 16:50:39 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5898784A53; Fri, 9 Feb 2024 16:50:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497437; cv=none; b=Z3XwEGsttlAlfdG3leURUsdCWupPc2HOs1hsXRVVLQTnU2hkiGwhwYTod30iKHUOD1oD6AKPAaOt52qZ+RGVG9Wu5FjMGBNmhERDnXcFZI/CXuAUQP52SfF799V0fc+AqPaJlvAJzLXKkcD2DWmtA74gs7TFFDlb/aG/qIIdodE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497437; c=relaxed/simple; bh=ZEhe0SxqzHrZlj/6A+VqGsB/kbYRr7eYGPNR25cnJcw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=SkydNlYkcmZGNg1X9RCfF1TlRv4rCsesgc3lVQ8cTooyvt728jZic6xDeGZeGzak0Ov0Duf1l4BA4o208wtIDsbt5QyxM/s27efRV2u9NvInOnnteO5Mr2188QE6vNTGflTnTRyKmdMgGSRqXtEhGzrsImjfuKYcnIA0Glba/N0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CC9B11576; Fri, 9 Feb 2024 08:51:16 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 029C93F64C; Fri, 9 Feb 2024 08:50:30 -0800 (PST) From: Robin Murphy To: Cc: Vineet Gupta , Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Suravee Suthikulpanit , David Woodhouse , Lu Baolu , Niklas Schnelle , Matthew Rosato , Gerald Schaefer , Jean-Philippe Brucker , Rob Herring , Frank Rowand , Marek Szyprowski , Jason Gunthorpe , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, iommu@lists.linux.dev, devicetree@vger.kernel.org, Jason Gunthorpe Subject: [PATCH v3 3/7] ACPI/IORT: Handle memory address size limits as limits Date: Fri, 9 Feb 2024 16:50:00 +0000 Message-Id: <5d52d580bf33d475053f9b05188fe3541cbe8798.1707493264.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.39.2.101.g768bb238c484.dirty In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790441609767518322 X-GMAIL-MSGID: 1790441609767518322 Return the Root Complex/Named Component memory address size limit as an inclusive limit value, rather than an exclusive size. This saves having to fudge an off-by-one for the 64-bit case, and simplifies our caller. Reviewed-by: Jason Gunthorpe Signed-off-by: Robin Murphy --- v2: Avoid undefined shifts (grr...) --- drivers/acpi/arm64/dma.c | 9 +++------ drivers/acpi/arm64/iort.c | 20 ++++++++++---------- include/linux/acpi_iort.h | 4 ++-- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/drivers/acpi/arm64/dma.c b/drivers/acpi/arm64/dma.c index 93d796531af3..b98a149f8d50 100644 --- a/drivers/acpi/arm64/dma.c +++ b/drivers/acpi/arm64/dma.c @@ -8,7 +8,6 @@ void acpi_arch_dma_setup(struct device *dev) { int ret; u64 end, mask; - u64 size = 0; const struct bus_dma_region *map = NULL; /* @@ -23,9 +22,9 @@ void acpi_arch_dma_setup(struct device *dev) } if (dev->coherent_dma_mask) - size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1); + end = dev->coherent_dma_mask; else - size = 1ULL << 32; + end = (1ULL << 32) - 1; ret = acpi_dma_get_range(dev, &map); if (!ret && map) { @@ -36,18 +35,16 @@ void acpi_arch_dma_setup(struct device *dev) end = r->dma_start + r->size - 1; } - size = end + 1; dev->dma_range_map = map; } if (ret == -ENODEV) - ret = iort_dma_get_ranges(dev, &size); + ret = iort_dma_get_ranges(dev, &end); if (!ret) { /* * Limit coherent and dma mask based on size retrieved from * firmware. */ - end = size - 1; mask = DMA_BIT_MASK(ilog2(end) + 1); dev->bus_dma_limit = end; dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask); diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c index 6496ff5a6ba2..c0b1c2c19444 100644 --- a/drivers/acpi/arm64/iort.c +++ b/drivers/acpi/arm64/iort.c @@ -1367,7 +1367,7 @@ int iort_iommu_configure_id(struct device *dev, const u32 *input_id) { return -ENODEV; } #endif -static int nc_dma_get_range(struct device *dev, u64 *size) +static int nc_dma_get_range(struct device *dev, u64 *limit) { struct acpi_iort_node *node; struct acpi_iort_named_component *ncomp; @@ -1384,13 +1384,13 @@ static int nc_dma_get_range(struct device *dev, u64 *size) return -EINVAL; } - *size = ncomp->memory_address_limit >= 64 ? U64_MAX : - 1ULL<memory_address_limit; + *limit = ncomp->memory_address_limit >= 64 ? U64_MAX : + (1ULL << ncomp->memory_address_limit) - 1; return 0; } -static int rc_dma_get_range(struct device *dev, u64 *size) +static int rc_dma_get_range(struct device *dev, u64 *limit) { struct acpi_iort_node *node; struct acpi_iort_root_complex *rc; @@ -1408,8 +1408,8 @@ static int rc_dma_get_range(struct device *dev, u64 *size) return -EINVAL; } - *size = rc->memory_address_limit >= 64 ? U64_MAX : - 1ULL<memory_address_limit; + *limit = rc->memory_address_limit >= 64 ? U64_MAX : + (1ULL << rc->memory_address_limit) - 1; return 0; } @@ -1417,16 +1417,16 @@ static int rc_dma_get_range(struct device *dev, u64 *size) /** * iort_dma_get_ranges() - Look up DMA addressing limit for the device * @dev: device to lookup - * @size: DMA range size result pointer + * @limit: DMA limit result pointer * * Return: 0 on success, an error otherwise. */ -int iort_dma_get_ranges(struct device *dev, u64 *size) +int iort_dma_get_ranges(struct device *dev, u64 *limit) { if (dev_is_pci(dev)) - return rc_dma_get_range(dev, size); + return rc_dma_get_range(dev, limit); else - return nc_dma_get_range(dev, size); + return nc_dma_get_range(dev, limit); } static void __init acpi_iort_register_irq(int hwirq, const char *name, diff --git a/include/linux/acpi_iort.h b/include/linux/acpi_iort.h index 1cb65592c95d..d4ed5622cf2b 100644 --- a/include/linux/acpi_iort.h +++ b/include/linux/acpi_iort.h @@ -39,7 +39,7 @@ void iort_get_rmr_sids(struct fwnode_handle *iommu_fwnode, void iort_put_rmr_sids(struct fwnode_handle *iommu_fwnode, struct list_head *head); /* IOMMU interface */ -int iort_dma_get_ranges(struct device *dev, u64 *size); +int iort_dma_get_ranges(struct device *dev, u64 *limit); int iort_iommu_configure_id(struct device *dev, const u32 *id_in); void iort_iommu_get_resv_regions(struct device *dev, struct list_head *head); phys_addr_t acpi_iort_dma_get_max_cpu_address(void); @@ -55,7 +55,7 @@ void iort_get_rmr_sids(struct fwnode_handle *iommu_fwnode, struct list_head *hea static inline void iort_put_rmr_sids(struct fwnode_handle *iommu_fwnode, struct list_head *head) { } /* IOMMU interface */ -static inline int iort_dma_get_ranges(struct device *dev, u64 *size) +static inline int iort_dma_get_ranges(struct device *dev, u64 *limit) { return -ENODEV; } static inline int iort_iommu_configure_id(struct device *dev, const u32 *id_in) { return -ENODEV; } From patchwork Fri Feb 9 16:50:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 199004 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp985834dyd; Fri, 9 Feb 2024 08:56:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGond5YfBlfSbV76Wg78Epn+XjZ/qNQw+crb2cu/Rn6jsFSnPnVxJHR4Rsc5FAEnviskfs3 X-Received: by 2002:a05:6402:649:b0:560:9255:7580 with SMTP id u9-20020a056402064900b0056092557580mr2130813edx.17.1707497761892; Fri, 09 Feb 2024 08:56:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707497761; cv=pass; d=google.com; s=arc-20160816; b=IBHlHPt5uzh/F1mCNjNIAKBBt37X5dnkN3NjgCGudF1p58Veo6amPoTfNp+NNvlqv6 fNqyQ7w2qtpfZUORp8I7CmDM4CDI5RaNWa8uHF3D920dT7uy92AKF8tW6jBaVZzfoWRp x8mtSVMg9paB2W8kF0/VBuQgTjBwzrJfKpEriPlIOjN+Szd+SXVFYFinlpoBw46t2hTh VRjHBXx8FS2EhOco9mIdgYQ5R+tWbwBfxHNzvWmWPo53YLnh1MtpChezPSaJsgzF3qev bik1zuofr3yTGjtRTflVJbGR9IOh4RiVltfhDS94toF9VAwkVhHNcKZ9pnXIOPG+eZNa 52dg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=dabkLraXIIijrJwTv2DH8ou0CHhgI6xbXomRUibwvN8=; fh=swCsI5k4yfFjchCGAtly0b9TCGiYLQ0R5uhNmkAJhaA=; b=NwU+UbdL3Rop8IzFn7e00T88FXUxS65M434L352nJOhSfbzMM4XU1lGhmN0Qma+KvU 8jQ27fh3ByHG3ag5d/qmqFO77vx+w3lebAtXX+2c6va7+P8ObYAGyYqYLL8mdm6w5ybM /DZUHt/fUJKk0t0uuSz69zmkv9fo4fDDvF7/SgxU7L9P64X3TmeMIOK9i3oiM+giF7Jr JW8V5S6QAXX2JKe4iXRauh+ES+G8cE067S/xs0kAg/Or2a8TbrsK/0cCVS+9qIpM9WhC CLfScXO1AYV3NY3fNswBMA7IbUBIbpWpDAt0cdwMA3ueyYi1sfJO7XLl6o7aNJ7GZU1F tfZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-59676-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59676-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCVGqeEKRqJNPrRWTWwVFEXPb9Ee3ZuwIJR4OsTBDRDc8fkXbD6Ug4QNKy0R8EmXBWw6ZI9NwFWn+Ocbr7GmfVQWH1HcRQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d15-20020a056402078f00b00560f3a68af4si1072940edy.355.2024.02.09.08.56.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 08:56:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59676-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-59676-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59676-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 83AA71F211F6 for ; Fri, 9 Feb 2024 16:56:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 28D7A12BEA7; Fri, 9 Feb 2024 16:50:44 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9798812B15D; Fri, 9 Feb 2024 16:50:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497442; cv=none; b=XmN0xumVhp0jkPWiMVaZl0HiP8CBOsQgqy46oEMCwrzNdBvcsQ8qNeOsYW/NWH4zy9ixFGkCVpNjAXexbDASFV4FA3CR5j4wI2RVNcKddecop8kI5ZZsizGA1KPe0AaC4C/VBicvkBgNccR7xCiazAl7qpiG4OQ8oKfeMifX1gY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497442; c=relaxed/simple; bh=xTtinJLnaC/I9VC5UbTSJ2+ulMHcbqG/ydth+2lej9Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Q++7b1V9VxKSQQFC75cgdNZTWGNhJlFAtS959fSvFf8+Gk1Aqz5MlOX2UGXRGMjMEOYmfFe/57CO2uisJ88JTbfrwx0/nxfhxIjnznXVNIfHakw3oqSK29foV4WV6RxYz7O6YUAUlyDKDOr+IvJCJ7CkMAq1FrCju/F6QrxEE5Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 11730DA7; Fri, 9 Feb 2024 08:51:21 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 08BD53F64C; Fri, 9 Feb 2024 08:50:34 -0800 (PST) From: Robin Murphy To: Cc: Vineet Gupta , Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Suravee Suthikulpanit , David Woodhouse , Lu Baolu , Niklas Schnelle , Matthew Rosato , Gerald Schaefer , Jean-Philippe Brucker , Rob Herring , Frank Rowand , Marek Szyprowski , Jason Gunthorpe , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, iommu@lists.linux.dev, devicetree@vger.kernel.org, Rob Herring , Christoph Hellwig , Jason Gunthorpe Subject: [PATCH v3 4/7] dma-mapping: Add helpers for dma_range_map bounds Date: Fri, 9 Feb 2024 16:50:01 +0000 Message-Id: X-Mailer: git-send-email 2.39.2.101.g768bb238c484.dirty In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790441173400062946 X-GMAIL-MSGID: 1790441173400062946 Several places want to compute the lower and/or upper bounds of a dma_range_map, so let's factor that out into reusable helpers. Acked-by: Rob Herring Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Signed-off-by: Robin Murphy --- v2: fix warning for 32-bit builds --- arch/loongarch/kernel/dma.c | 9 ++------- drivers/acpi/arm64/dma.c | 8 +------- drivers/of/device.c | 11 ++--------- include/linux/dma-direct.h | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/arch/loongarch/kernel/dma.c b/arch/loongarch/kernel/dma.c index 7a9c6a9dd2d0..429555fb4e13 100644 --- a/arch/loongarch/kernel/dma.c +++ b/arch/loongarch/kernel/dma.c @@ -8,17 +8,12 @@ void acpi_arch_dma_setup(struct device *dev) { int ret; - u64 mask, end = 0; + u64 mask, end; const struct bus_dma_region *map = NULL; ret = acpi_dma_get_range(dev, &map); if (!ret && map) { - const struct bus_dma_region *r = map; - - for (end = 0; r->size; r++) { - if (r->dma_start + r->size - 1 > end) - end = r->dma_start + r->size - 1; - } + end = dma_range_map_max(map); mask = DMA_BIT_MASK(ilog2(end) + 1); dev->bus_dma_limit = end; diff --git a/drivers/acpi/arm64/dma.c b/drivers/acpi/arm64/dma.c index b98a149f8d50..52b2abf88689 100644 --- a/drivers/acpi/arm64/dma.c +++ b/drivers/acpi/arm64/dma.c @@ -28,13 +28,7 @@ void acpi_arch_dma_setup(struct device *dev) ret = acpi_dma_get_range(dev, &map); if (!ret && map) { - const struct bus_dma_region *r = map; - - for (end = 0; r->size; r++) { - if (r->dma_start + r->size - 1 > end) - end = r->dma_start + r->size - 1; - } - + end = dma_range_map_max(map); dev->dma_range_map = map; } diff --git a/drivers/of/device.c b/drivers/of/device.c index 841ccd3a19d1..9e7963972fa7 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -117,16 +117,9 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, if (!force_dma) return ret == -ENODEV ? 0 : ret; } else { - const struct bus_dma_region *r = map; - /* Determine the overall bounds of all DMA regions */ - for (dma_start = ~0; r->size; r++) { - /* Take lower and upper limits */ - if (r->dma_start < dma_start) - dma_start = r->dma_start; - if (r->dma_start + r->size > end) - end = r->dma_start + r->size; - } + dma_start = dma_range_map_min(map); + end = dma_range_map_max(map); } /* diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h index 3eb3589ff43e..edbe13d00776 100644 --- a/include/linux/dma-direct.h +++ b/include/linux/dma-direct.h @@ -54,6 +54,24 @@ static inline phys_addr_t translate_dma_to_phys(struct device *dev, return (phys_addr_t)-1; } +static inline dma_addr_t dma_range_map_min(const struct bus_dma_region *map) +{ + dma_addr_t ret = (dma_addr_t)U64_MAX; + + for (; map->size; map++) + ret = min(ret, map->dma_start); + return ret; +} + +static inline dma_addr_t dma_range_map_max(const struct bus_dma_region *map) +{ + dma_addr_t ret = 0; + + for (; map->size; map++) + ret = max(ret, map->dma_start + map->size - 1); + return ret; +} + #ifdef CONFIG_ARCH_HAS_PHYS_TO_DMA #include #ifndef phys_to_dma_unencrypted From patchwork Fri Feb 9 16:50:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 199009 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp986940dyd; Fri, 9 Feb 2024 08:58:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHiJtcPPPLn7WIHrOxIStDknhHyPrIOQuBWTXXuNHEwrcTO+t9GmW50iSGM0N7C93cUF6bo X-Received: by 2002:a17:906:b785:b0:a3b:da9b:b0a2 with SMTP id dt5-20020a170906b78500b00a3bda9bb0a2mr1707966ejb.58.1707497898271; Fri, 09 Feb 2024 08:58:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707497898; cv=pass; d=google.com; s=arc-20160816; b=KvW/BtdtooGztixUBFFPSgkraN6D746OsnVw+Hf/oAjWnImn5oleJzwDEl8hrbBBYk CkpSPjqKSh7ZXPRWElAEqWzQy2xLLhex0upfj/0WtJgjOzeGs/qs4VX8evdmbCa2/asg xiCwhXf3Spr8tfRMGhT2JpaxMGlJ7Rms5aIvS9DctfCxLqNWEJYUNVV2Ua/VPxuMfO1X BrELq7xPNeu5aTgGZNZXCU5ZEKE4JDZP1ZkVUR8e0nZ/XxNq5zwG5f1I3AnhMAhCctkJ 458nJXPC1ivoOEj/DDo7hBQGEz4SQ5Dy8uxEzwSjipooUhSWvxuG8/Z0+Gu5HuoiUpLl xpAg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=NlYGiQUIL1AWDeI9EzH0PMTx88FpBDXp1HdUQ9aWn4Q=; fh=1OqgcuUI93kwySFiKdNbmhYuM5Z0hpBP3JPHUx3Hu0I=; b=GKCs3JoIhMQZtI25TrqFtD5oUTUqUdnqQy56x2xhaqkA1Zw6lpA71r8OyEqnAsBDPO T0tuwkmFRBQZDkcrYokXIC+FfR40bMFN+azlldExlLzZ6XgiSpT9tlJ9hrVDFR8KXLlS TX1Z2qTHKy9uFuRAl6TiM2ZXd0bndMekrm24ixEcWP522OsKyf2dxCqIVLY2ykmxKHzF P4SwmeVfNCE5/3hn7nl8bABMlfNTMJ1eLheATE3OETPSggYsN885PFJhngUVmW8NKUz2 sK3/S2HQVB9zt4oNx8REG5t7+QuZU1xOqkwDE5BguE0DjVPMY0l//3mtEzJDKc4hOO7y bNKg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-59678-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59678-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCWDM3qE0i7uJ8MKCf9q1PrQSPKCKMn9+uP9Fc0CqHHdxl+vDlyu/TI/BxgATuOrtFI0kA2Q2Yqu+/KTab0IVJZBnK+hlA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bq10-20020a170906d0ca00b00a3785efe1casi978453ejb.941.2024.02.09.08.58.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 08:58:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59678-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-59678-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59678-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8F7BE1F25018 for ; Fri, 9 Feb 2024 16:56:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 88C3C126F3F; Fri, 9 Feb 2024 16:50:53 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 88EB512BE9C; Fri, 9 Feb 2024 16:50:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497450; cv=none; b=Ak7unO8aoFM5mVwSfkom2m3Cc8F8ojPM1cT7SL5QfYmzhm1vTKEC0NXlqWjgvQPbxCu66kKgPUMEe7p08BymaCUfHig2VaVY96acn0+f/bHeEFodaqGVfnmNo00kAXGD8U6p/m/qn74O1U+y+2VEXVLwQ1y6SuQOHbARfKfus5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497450; c=relaxed/simple; bh=BjqBw3BXFHDla5pW2JiQZ7jV29wfW+1kwBA6lu0tHGU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N/NMCOtmcrNJ+hhUsBtFuSqiEFEi+ZQjMdWco+XXQDAvxHTl5Vb8yHsLc6VAgzwlwE8HXkpwlDkj8A2BQ4IQVIHE0QHR62rBFsPRiM2BgK7IZSHW7sAcoWZVroMa7OXKNdfDirFRpVYaagBRLxW6uHhavXKMjOI0SVhLLiZXpaA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0515BDA7; Fri, 9 Feb 2024 08:51:29 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 495793F64C; Fri, 9 Feb 2024 08:50:43 -0800 (PST) From: Robin Murphy To: Cc: Vineet Gupta , Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Suravee Suthikulpanit , David Woodhouse , Lu Baolu , Niklas Schnelle , Matthew Rosato , Gerald Schaefer , Jean-Philippe Brucker , Rob Herring , Frank Rowand , Marek Szyprowski , Jason Gunthorpe , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, iommu@lists.linux.dev, devicetree@vger.kernel.org Subject: [PATCH v3 6/7] iommu/dma: Centralise iommu_setup_dma_ops() Date: Fri, 9 Feb 2024 16:50:03 +0000 Message-Id: <202fcca3269201bc9c4a8198253f195433d0c4ff.1707493264.git.robin.murphy@arm.com> X-Mailer: git-send-email 2.39.2.101.g768bb238c484.dirty In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790441316091966902 X-GMAIL-MSGID: 1790441316091966902 It's somewhat hard to see, but arm64's arch_setup_dma_ops() should only ever call iommu_setup_dma_ops() after a successful iommu_probe_device(), which means there should be no harm in achieving the same order of operations by running it off the back of iommu_probe_device() itself. This then puts it in line with the x86 and s390 .probe_finalize bodges, letting us pull it all into the main flow properly. As a bonus this lets us fold in and de-scope the PCI workaround setup as well. At this point we can also then pull the call up inside the group mutex, and avoid having to think about whether iommu_group_store_type() could theoretically race and free the domain if iommu_setup_dma_ops() ran just *before* iommu_device_use_default_domain() claims it... Furthermore we replace one .probe_finalize call completely, since the only remaining implementations are now one which only needs to run once for the initial boot-time probe, and two which themselves render that path unreachable. This leaves us a big step closer to realistically being able to unpick the variety of different things that iommu_setup_dma_ops() has been muddling together, and further streamline iommu-dma into core API flows in future. Signed-off-by: Robin Murphy Reviewed-by: Lu Baolu --- v2: Shuffle around to make sure the iommu_group_do_probe_finalize() case is covered as well, with bonus side-effects as above. v3: *Really* do that, remembering the other two probe_finalize sites too. --- arch/arm64/mm/dma-mapping.c | 2 -- drivers/iommu/amd/iommu.c | 8 -------- drivers/iommu/dma-iommu.c | 18 ++++++------------ drivers/iommu/dma-iommu.h | 14 ++++++-------- drivers/iommu/intel/iommu.c | 7 ------- drivers/iommu/iommu.c | 20 +++++++------------- drivers/iommu/s390-iommu.c | 6 ------ drivers/iommu/virtio-iommu.c | 10 ---------- include/linux/iommu.h | 7 ------- 9 files changed, 19 insertions(+), 73 deletions(-) diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 61886e43e3a1..313d8938a2f0 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -58,8 +58,6 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, ARCH_DMA_MINALIGN, cls); dev->dma_coherent = coherent; - if (device_iommu_mapped(dev)) - iommu_setup_dma_ops(dev, dma_base, dma_base + size - 1); xen_setup_dma_ops(dev); } diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 4283dd8191f0..00c0d5de1225 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1968,13 +1968,6 @@ static struct iommu_device *amd_iommu_probe_device(struct device *dev) return iommu_dev; } -static void amd_iommu_probe_finalize(struct device *dev) -{ - /* Domains are initialized for this device - have a look what we ended up with */ - set_dma_ops(dev, NULL); - iommu_setup_dma_ops(dev, 0, U64_MAX); -} - static void amd_iommu_release_device(struct device *dev) { struct amd_iommu *iommu; @@ -2626,7 +2619,6 @@ const struct iommu_ops amd_iommu_ops = { .domain_alloc_user = amd_iommu_domain_alloc_user, .probe_device = amd_iommu_probe_device, .release_device = amd_iommu_release_device, - .probe_finalize = amd_iommu_probe_finalize, .device_group = amd_iommu_device_group, .get_resv_regions = amd_iommu_get_resv_regions, .is_attach_deferred = amd_iommu_is_attach_deferred, diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 52126f73f690..fa1cdca39da6 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -1727,25 +1727,20 @@ static const struct dma_map_ops iommu_dma_ops = { .opt_mapping_size = iommu_dma_opt_mapping_size, }; -/* - * The IOMMU core code allocates the default DMA domain, which the underlying - * IOMMU driver needs to support via the dma-iommu layer. - */ -void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 dma_limit) +void iommu_setup_dma_ops(struct device *dev) { struct iommu_domain *domain = iommu_get_domain_for_dev(dev); - if (!domain) - goto out_err; + if (dev_is_pci(dev)) + dev->iommu->pci_32bit_workaround = !iommu_dma_forcedac; - /* - * The IOMMU core code allocates the default DMA domain, which the - * underlying IOMMU driver needs to support via the dma-iommu layer. - */ if (iommu_is_dma_domain(domain)) { if (iommu_dma_init_domain(domain, dev)) goto out_err; dev->dma_ops = &iommu_dma_ops; + } else if (dev->dma_ops == &iommu_dma_ops) { + /* Clean up if we've switched *from* a DMA domain */ + dev->dma_ops = NULL; } return; @@ -1753,7 +1748,6 @@ void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 dma_limit) pr_warn("Failed to set up IOMMU for device %s; retaining platform DMA ops\n", dev_name(dev)); } -EXPORT_SYMBOL_GPL(iommu_setup_dma_ops); static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev, phys_addr_t msi_addr, struct iommu_domain *domain) diff --git a/drivers/iommu/dma-iommu.h b/drivers/iommu/dma-iommu.h index c829f1f82a99..c12d63457c76 100644 --- a/drivers/iommu/dma-iommu.h +++ b/drivers/iommu/dma-iommu.h @@ -9,6 +9,8 @@ #ifdef CONFIG_IOMMU_DMA +void iommu_setup_dma_ops(struct device *dev); + int iommu_get_dma_cookie(struct iommu_domain *domain); void iommu_put_dma_cookie(struct iommu_domain *domain); @@ -17,13 +19,13 @@ int iommu_dma_init_fq(struct iommu_domain *domain); void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list); extern bool iommu_dma_forcedac; -static inline void iommu_dma_set_pci_32bit_workaround(struct device *dev) -{ - dev->iommu->pci_32bit_workaround = !iommu_dma_forcedac; -} #else /* CONFIG_IOMMU_DMA */ +static inline void iommu_setup_dma_ops(struct device *dev) +{ +} + static inline int iommu_dma_init_fq(struct iommu_domain *domain) { return -EINVAL; @@ -42,9 +44,5 @@ static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_he { } -static inline void iommu_dma_set_pci_32bit_workaround(struct device *dev) -{ -} - #endif /* CONFIG_IOMMU_DMA */ #endif /* __DMA_IOMMU_H */ diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 6fb5f6fceea1..f1c599429408 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -4291,12 +4291,6 @@ static void intel_iommu_release_device(struct device *dev) set_dma_ops(dev, NULL); } -static void intel_iommu_probe_finalize(struct device *dev) -{ - set_dma_ops(dev, NULL); - iommu_setup_dma_ops(dev, 0, U64_MAX); -} - static void intel_iommu_get_resv_regions(struct device *device, struct list_head *head) { @@ -4748,7 +4742,6 @@ const struct iommu_ops intel_iommu_ops = { .domain_alloc = intel_iommu_domain_alloc, .domain_alloc_user = intel_iommu_domain_alloc_user, .probe_device = intel_iommu_probe_device, - .probe_finalize = intel_iommu_probe_finalize, .release_device = intel_iommu_release_device, .get_resv_regions = intel_iommu_get_resv_regions, .device_group = intel_iommu_device_group, diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index d14413916f93..e793b2f4bdc8 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -571,10 +571,11 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list if (list_empty(&group->entry)) list_add_tail(&group->entry, group_list); } - mutex_unlock(&group->mutex); - if (dev_is_pci(dev)) - iommu_dma_set_pci_32bit_workaround(dev); + if (group->default_domain) + iommu_setup_dma_ops(dev); + + mutex_unlock(&group->mutex); return 0; @@ -2010,6 +2011,8 @@ int bus_iommu_probe(const struct bus_type *bus) mutex_unlock(&group->mutex); return ret; } + for_each_group_device(group, gdev) + iommu_setup_dma_ops(gdev->dev); mutex_unlock(&group->mutex); /* @@ -3248,18 +3251,9 @@ static ssize_t iommu_group_store_type(struct iommu_group *group, if (ret) goto out_unlock; - /* - * Release the mutex here because ops->probe_finalize() call-back of - * some vendor IOMMU drivers calls arm_iommu_attach_device() which - * in-turn might call back into IOMMU core code, where it tries to take - * group->mutex, resulting in a deadlock. - */ - mutex_unlock(&group->mutex); - /* Make sure dma_ops is appropriatley set */ for_each_group_device(group, gdev) - iommu_group_do_probe_finalize(gdev->dev); - return count; + iommu_setup_dma_ops(gdev->dev); out_unlock: mutex_unlock(&group->mutex); diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c index 9a5196f523de..d8eaa7ea380b 100644 --- a/drivers/iommu/s390-iommu.c +++ b/drivers/iommu/s390-iommu.c @@ -695,11 +695,6 @@ static size_t s390_iommu_unmap_pages(struct iommu_domain *domain, return size; } -static void s390_iommu_probe_finalize(struct device *dev) -{ - iommu_setup_dma_ops(dev, 0, U64_MAX); -} - struct zpci_iommu_ctrs *zpci_get_iommu_ctrs(struct zpci_dev *zdev) { if (!zdev || !zdev->s390_domain) @@ -785,7 +780,6 @@ static const struct iommu_ops s390_iommu_ops = { .capable = s390_iommu_capable, .domain_alloc_paging = s390_domain_alloc_paging, .probe_device = s390_iommu_probe_device, - .probe_finalize = s390_iommu_probe_finalize, .release_device = s390_iommu_release_device, .device_group = generic_device_group, .pgsize_bitmap = SZ_4K, diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index 34db37fd9675..ec7640127125 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -1025,15 +1025,6 @@ static struct iommu_device *viommu_probe_device(struct device *dev) return ERR_PTR(ret); } -static void viommu_probe_finalize(struct device *dev) -{ -#ifndef CONFIG_ARCH_HAS_SETUP_DMA_OPS - /* First clear the DMA ops in case we're switching from a DMA domain */ - set_dma_ops(dev, NULL); - iommu_setup_dma_ops(dev, 0, U64_MAX); -#endif -} - static void viommu_release_device(struct device *dev) { struct viommu_endpoint *vdev = dev_iommu_priv_get(dev); @@ -1072,7 +1063,6 @@ static struct iommu_ops viommu_ops = { .capable = viommu_capable, .domain_alloc = viommu_domain_alloc, .probe_device = viommu_probe_device, - .probe_finalize = viommu_probe_finalize, .release_device = viommu_release_device, .device_group = viommu_device_group, .get_resv_regions = viommu_get_resv_regions, diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 79c3dac8be75..509add6699c8 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -1367,9 +1367,6 @@ static inline void iommu_debugfs_setup(void) {} #ifdef CONFIG_IOMMU_DMA #include -/* Setup call for arch DMA mapping code */ -void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 dma_limit); - int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base); int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr); @@ -1380,10 +1377,6 @@ void iommu_dma_compose_msi_msg(struct msi_desc *desc, struct msi_msg *msg); struct msi_desc; struct msi_msg; -static inline void iommu_setup_dma_ops(struct device *dev, u64 dma_base, u64 dma_limit) -{ -} - static inline int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base) { return -ENODEV; From patchwork Fri Feb 9 16:50:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Murphy X-Patchwork-Id: 199008 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp986881dyd; Fri, 9 Feb 2024 08:58:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV7rCFcchm/Bik/Mu9bSG9UWbPXTKqTp/FjCHOvBe/lfzk2nVSicEEHOvmZUcOQ0QrZEcPe184T7Pnr6FhWV39ycBP2+g== X-Google-Smtp-Source: AGHT+IF8M1m92C+w50r10sgiHZwQ15pIE6E6Y6Eh2W58kxkQBpCi6rvoWhirB3vFTrmv7owZhrGY X-Received: by 2002:ac8:7f86:0:b0:42c:bb8:f69a with SMTP id z6-20020ac87f86000000b0042c0bb8f69amr2130640qtj.58.1707497892587; Fri, 09 Feb 2024 08:58:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707497892; cv=pass; d=google.com; s=arc-20160816; b=Dcjx37hoNQLx4fs3YTdoHW7WsDoCCbtdKZntyTOfzOwxKOzQzU5Wtc6dcNd3+EHis0 3GbBnA+z9Emv2sVn66qGmA+18PWeuqD7IJNUI1fUMxYqtW477RwkSYTLJ3BgAYt9nJBQ W1w5wvlyh6T7h3fHujPP4BGDvif41Wmmly5iK6T2L2jbWNpfvGRTGb7onTcK3oR903SL AZU+Rln3HbUATCV6CjcBtGCeExjHrxDm+wpVQaEYSVvfGmplqnwLx9tL8RTowweCmZaE sjQJVuUmZ/bePuJK6JxqTNkLu2JRJyJRGEfalj8kCNzxwyVRzRBimL0LKl2VnmXdXbb8 wbiQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=5J7wKZ1KLbW4eSRO7AUJaO5K+NfQrFK/8dLPi3HDMkQ=; fh=C9ZmuXZAnP98XbuXQB6axbu2MvMg3oZ1m41EfpG3u1Q=; b=j/7KD72GOnD0qtjpJj6fTWXkrmPqU/Kk0EyVlyuxN2CmA82GHEcm/EaXhic7Dcbh+G +ziJie8iBiyKy6zX2RJWQ76NH2bfqK/+EJ6O9XxBSnmxX/yCf6GZh7R33knbfDsDQxfh dhfH5JUvVd6EEg5DTswIquxiPphdogzQf1Y7HxDbG51kGygJvwPe81S3mfHJVXH72VzK IXNwn5vfi7v1FDrb/mhOJy0YeSTHf5eUQl8tc3UwT8okpUAXV4Ik43zkVNaXfiVXAlJF PewHoOo49wo0wBgX4qvB2ZERCEN06dd5TtLq7VrtnZQSEmpVdv/D1Eko0E0nr47DFdmo nvaA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-59679-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59679-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCWHtLlGQjakpuOC72fezp//sf80tbKBc3w/+XQafDxGT0t/H8dyBaDqi4GWGnrrkFehmaYoGeIrgV6lwqgI8schoFeGLg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g12-20020ac85d4c000000b0042c2aa87896si2335834qtx.2.2024.02.09.08.58.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 08:58:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59679-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-59679-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59679-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DD3511C268CC for ; Fri, 9 Feb 2024 16:56:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BAED712C523; Fri, 9 Feb 2024 16:50:56 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8DD5D12BF21; Fri, 9 Feb 2024 16:50:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497454; cv=none; b=C/+vgVkbMU8uYbKugGzFJdJTgSXmUJZ0Pme04Z18Sr6Kv7E5vM/PktFwE4fUc5EjeazpQ/35avx6+5TBkfjIAFW64onpqug5kE9lYxPn86R2KBJEK1LvkzQnkKO1Kry9TywbmYH9BMZJKmCIbfSdk2Wj5pE5AmTo26sykue/7Uw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497454; c=relaxed/simple; bh=BAgEyvhJwFjzB0KC6eWxcuhNCR9bxn/5R48JQV3EcQw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GAv5gKzI5uEcTP3whGK0zJzgVIQfc/FuL9y9fRy7oWc56d5kiKjZOMEZLRKOIy6CQettHSloZDsszakCe83H+IJhJg4J6SQgCYHICMdoOCJejrmOWoXi4iQb5hcZDzOo6v3C+WwzyuxskncDQDdsoHn9w0GglX21TOmC8gi/4pY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 24B7FFEC; Fri, 9 Feb 2024 08:51:33 -0800 (PST) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 363293F64C; Fri, 9 Feb 2024 08:50:47 -0800 (PST) From: Robin Murphy To: Cc: Vineet Gupta , Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Paul Walmsley , Palmer Dabbelt , Albert Ou , Lorenzo Pieralisi , Hanjun Guo , Sudeep Holla , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Suravee Suthikulpanit , David Woodhouse , Lu Baolu , Niklas Schnelle , Matthew Rosato , Gerald Schaefer , Jean-Philippe Brucker , Rob Herring , Frank Rowand , Marek Szyprowski , Jason Gunthorpe , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, iommu@lists.linux.dev, devicetree@vger.kernel.org, Rob Herring , Christoph Hellwig Subject: [PATCH v3 7/7] dma-mapping: Simplify arch_setup_dma_ops() Date: Fri, 9 Feb 2024 16:50:04 +0000 Message-Id: X-Mailer: git-send-email 2.39.2.101.g768bb238c484.dirty In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790441083377647931 X-GMAIL-MSGID: 1790441310294073758 The dma_base, size and iommu arguments are only used by ARM, and can now easily be deduced from the device itself, so there's no need to pass them through the callchain as well. Acked-by: Rob Herring Reviewed-by: Christoph Hellwig Signed-off-by: Robin Murphy Reviewed-by: Michael Kelley --- v2: Make sure the ARM changes actually build (oops...) --- arch/arc/mm/dma.c | 3 +-- arch/arm/mm/dma-mapping-nommu.c | 3 +-- arch/arm/mm/dma-mapping.c | 16 +++++++++------- arch/arm64/mm/dma-mapping.c | 3 +-- arch/mips/mm/dma-noncoherent.c | 3 +-- arch/riscv/mm/dma-noncoherent.c | 3 +-- drivers/acpi/scan.c | 7 +------ drivers/hv/hv_common.c | 6 +----- drivers/of/device.c | 4 +--- include/linux/dma-map-ops.h | 6 ++---- 10 files changed, 19 insertions(+), 35 deletions(-) diff --git a/arch/arc/mm/dma.c b/arch/arc/mm/dma.c index 197707bc7658..6b85e94f3275 100644 --- a/arch/arc/mm/dma.c +++ b/arch/arc/mm/dma.c @@ -90,8 +90,7 @@ void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size, /* * Plug in direct dma map ops. */ -void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, - bool coherent) +void arch_setup_dma_ops(struct device *dev, bool coherent) { /* * IOC hardware snoops all DMA traffic keeping the caches consistent diff --git a/arch/arm/mm/dma-mapping-nommu.c b/arch/arm/mm/dma-mapping-nommu.c index b94850b57995..97db5397c320 100644 --- a/arch/arm/mm/dma-mapping-nommu.c +++ b/arch/arm/mm/dma-mapping-nommu.c @@ -33,8 +33,7 @@ void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size, } } -void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, - bool coherent) +void arch_setup_dma_ops(struct device *dev, bool coherent) { if (IS_ENABLED(CONFIG_CPU_V7M)) { /* diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index f68db05eba29..5adf1769eee4 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1709,11 +1709,15 @@ void arm_iommu_detach_device(struct device *dev) } EXPORT_SYMBOL_GPL(arm_iommu_detach_device); -static void arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size, - bool coherent) +static void arm_setup_iommu_dma_ops(struct device *dev) { struct dma_iommu_mapping *mapping; + u64 dma_base = 0, size = 1ULL << 32; + if (dev->dma_range_map) { + dma_base = dma_range_map_min(dev->dma_range_map); + size = dma_range_map_max(dev->dma_range_map) - dma_base; + } mapping = arm_iommu_create_mapping(dev->bus, dma_base, size); if (IS_ERR(mapping)) { pr_warn("Failed to create %llu-byte IOMMU mapping for device %s\n", @@ -1744,8 +1748,7 @@ static void arm_teardown_iommu_dma_ops(struct device *dev) #else -static void arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size, - bool coherent) +static void arm_setup_iommu_dma_ops(struct device *dev) { } @@ -1753,8 +1756,7 @@ static void arm_teardown_iommu_dma_ops(struct device *dev) { } #endif /* CONFIG_ARM_DMA_USE_IOMMU */ -void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, - bool coherent) +void arch_setup_dma_ops(struct device *dev, bool coherent) { /* * Due to legacy code that sets the ->dma_coherent flag from a bus @@ -1774,7 +1776,7 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, return; if (device_iommu_mapped(dev)) - arm_setup_iommu_dma_ops(dev, dma_base, size, coherent); + arm_setup_iommu_dma_ops(dev); xen_setup_dma_ops(dev); dev->archdata.dma_ops_setup = true; diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 313d8938a2f0..0b320a25a471 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -46,8 +46,7 @@ void arch_teardown_dma_ops(struct device *dev) } #endif -void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, - bool coherent) +void arch_setup_dma_ops(struct device *dev, bool coherent) { int cls = cache_line_size_of_cpu(); diff --git a/arch/mips/mm/dma-noncoherent.c b/arch/mips/mm/dma-noncoherent.c index 0f3cec663a12..ab4f2a75a7d0 100644 --- a/arch/mips/mm/dma-noncoherent.c +++ b/arch/mips/mm/dma-noncoherent.c @@ -137,8 +137,7 @@ void arch_sync_dma_for_cpu(phys_addr_t paddr, size_t size, #endif #ifdef CONFIG_ARCH_HAS_SETUP_DMA_OPS -void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, - bool coherent) +void arch_setup_dma_ops(struct device *dev, bool coherent) { dev->dma_coherent = coherent; } diff --git a/arch/riscv/mm/dma-noncoherent.c b/arch/riscv/mm/dma-noncoherent.c index 843107f834b2..cb89d7e0ba88 100644 --- a/arch/riscv/mm/dma-noncoherent.c +++ b/arch/riscv/mm/dma-noncoherent.c @@ -128,8 +128,7 @@ void arch_dma_prep_coherent(struct page *page, size_t size) ALT_CMO_OP(FLUSH, flush_addr, size, riscv_cbom_block_size); } -void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, - bool coherent) +void arch_setup_dma_ops(struct device *dev, bool coherent) { WARN_TAINT(!coherent && riscv_cbom_block_size > ARCH_DMA_MINALIGN, TAINT_CPU_OUT_OF_SPEC, diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index e6ed1ba91e5c..f5df17d11717 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -1640,12 +1640,7 @@ int acpi_dma_configure_id(struct device *dev, enum dev_dma_attr attr, if (ret == -EPROBE_DEFER) return -EPROBE_DEFER; - /* - * Historically this routine doesn't fail driver probing due to errors - * in acpi_iommu_configure_id() - */ - - arch_setup_dma_ops(dev, 0, U64_MAX, attr == DEV_DMA_COHERENT); + arch_setup_dma_ops(dev, attr == DEV_DMA_COHERENT); return 0; } diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index 0285a74363b3..0e2decd1167a 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -484,11 +484,7 @@ EXPORT_SYMBOL_GPL(hv_query_ext_cap); void hv_setup_dma_ops(struct device *dev, bool coherent) { - /* - * Hyper-V does not offer a vIOMMU in the guest - * VM, so pass 0/NULL for the IOMMU settings - */ - arch_setup_dma_ops(dev, 0, 0, coherent); + arch_setup_dma_ops(dev, coherent); } EXPORT_SYMBOL_GPL(hv_setup_dma_ops); diff --git a/drivers/of/device.c b/drivers/of/device.c index 9e7963972fa7..312c63361211 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -95,7 +95,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, { const struct bus_dma_region *map = NULL; struct device_node *bus_np; - u64 dma_start = 0; u64 mask, end = 0; bool coherent; int iommu_ret; @@ -118,7 +117,6 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, return ret == -ENODEV ? 0 : ret; } else { /* Determine the overall bounds of all DMA regions */ - dma_start = dma_range_map_min(map); end = dma_range_map_max(map); } @@ -175,7 +173,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, } else dev_dbg(dev, "device is behind an iommu\n"); - arch_setup_dma_ops(dev, dma_start, end - dma_start + 1, coherent); + arch_setup_dma_ops(dev, coherent); if (iommu_ret) of_dma_set_restricted_buffer(dev, np); diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h index 4abc60f04209..ed89e1ce0114 100644 --- a/include/linux/dma-map-ops.h +++ b/include/linux/dma-map-ops.h @@ -426,11 +426,9 @@ bool arch_dma_unmap_sg_direct(struct device *dev, struct scatterlist *sg, #endif #ifdef CONFIG_ARCH_HAS_SETUP_DMA_OPS -void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, - bool coherent); +void arch_setup_dma_ops(struct device *dev, bool coherent); #else -static inline void arch_setup_dma_ops(struct device *dev, u64 dma_base, - u64 size, bool coherent) +static inline void arch_setup_dma_ops(struct device *dev, bool coherent) { } #endif /* CONFIG_ARCH_HAS_SETUP_DMA_OPS */