Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1616571pxb; Mon, 11 Oct 2021 09:33:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzspfqKQCxA5Mx5djqlQGmrOcrcfsaXtrcQ35qTOJf9bMiCbSnANW7QcJkFmmRwejgICuNH X-Received: by 2002:a17:906:5a8d:: with SMTP id l13mr27919484ejq.95.1633970006574; Mon, 11 Oct 2021 09:33:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633970006; cv=none; d=google.com; s=arc-20160816; b=z9hlDw75r13rKABZ4OycbvmMHuKYgrSQXgRrHfN/uEvdJyWstnoHR8HoZQH0SqiWWH DH0lc19vHyBl2IgBhqFcwilKjyE74uTAnB/EX0j//uw5443KEZCs0/jyxYPskD8PF1NC aqO8M7H/qYcGKA2XGk9cyKD2JDBkoG14QKvnrx7j+mwSEbwmtiTU6muss1NMwok1OFqp Pf/E1m1SYLcvm1RA5VT6X4j21iy79Ca/5I6WAUkebARSEQHFf8T3jQkoe8GHzVr0n1xQ HUoZqWfsaqSex8lSbOTivJ5L9CST5u6kH2roz4k3h/Cce43nil69JY97hAhqZ667U8nd /uCA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/nASSbIZcqXIxSpMk/vAilXHY8a1UFxNhQCapvnledU=; b=0ey6CuwgLY7eXyOGoNT8cuIQJBs+2Vouy8I6ZHqbOc/42BekJqCV2cQgEkwLLoZ4my mCHpEBgEo8/oGkgXGJVMCvhSS4KPF99KJhc0S+iLAQKL87kMd4cH1whvPsGn4/RO0lVa hh/JZv/uPMIvWaIUisU/6wEXn7WAI/kQyN2kkOCrym4rCQk4YLzd0pjLjRp3Hv+IjdgG FeaJBYjM5FhEGZugXkRe+8MrzwmzD8N/FxlNa7QWHvC24eZYJ6mU5G0d54xvRKEQpv0i XZ1p/bDH+8Im7oz9dLksqkAatQy2rRDDZT23MwEubkrk68rQyR/gKk+Hhh1va8FVktuf +uHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=znPj3isn; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o11si10250726edc.51.2021.10.11.09.33.01; Mon, 11 Oct 2021 09:33:26 -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=@linuxfoundation.org header.s=korg header.b=znPj3isn; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237337AbhJKOAR (ORCPT + 99 others); Mon, 11 Oct 2021 10:00:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:49798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236894AbhJKN54 (ORCPT ); Mon, 11 Oct 2021 09:57:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C713360E8B; Mon, 11 Oct 2021 13:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633960470; bh=4RKgkISkbESJlFhvG4on8itP+82lxqG4cBxbchGuLV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=znPj3isn2JtSy/Xt4VpPU6zxH+y/fs8S+V6mPMwUdiY0kln0weD3l7m2d/cROKF6P Kno4slJ7vBYUTFDGLKlw7QQBCFjMrBRvoWmGxNcF6DcGLiaDuRzlA5NLaMxBso3a+z rNvfCd+H9n13fVsElyh3lIpAllTYDUTlkkYbvPJI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Kardashevskiy , Christoph Hellwig , Michael Ellerman , Sasha Levin Subject: [PATCH 5.10 67/83] powerpc/iommu: Report the correct most efficient DMA mask for PCI devices Date: Mon, 11 Oct 2021 15:46:27 +0200 Message-Id: <20211011134510.700666693@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011134508.362906295@linuxfoundation.org> References: <20211011134508.362906295@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexey Kardashevskiy [ Upstream commit 23c216b335d1fbd716076e8263b54a714ea3cf0e ] According to dma-api.rst, the dma_get_required_mask() helper should return "the mask that the platform requires to operate efficiently". Which in the case of PPC64 means the bypass mask and not a mask from an IOMMU table which is shorter and slower to use due to map/unmap operations (especially expensive on "pseries"). However the existing implementation ignores the possibility of bypassing and returns the IOMMU table mask on the pseries platform which makes some drivers (mpt3sas is one example) choose 32bit DMA even though bypass is supported. The powernv platform sort of handles it by having a bigger default window with a mask >=40 but it only works as drivers choose 63/64bit if the required mask is >32 which is rather pointless. This reintroduces the bypass capability check to let drivers make a better choice of the DMA mask. Fixes: f1565c24b596 ("powerpc: use the generic dma_ops_bypass mode") Signed-off-by: Alexey Kardashevskiy Reviewed-by: Christoph Hellwig Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20210930034454.95794-1-aik@ozlabs.ru Signed-off-by: Sasha Levin --- arch/powerpc/kernel/dma-iommu.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/powerpc/kernel/dma-iommu.c b/arch/powerpc/kernel/dma-iommu.c index a1c744194018..9ac0651795cf 100644 --- a/arch/powerpc/kernel/dma-iommu.c +++ b/arch/powerpc/kernel/dma-iommu.c @@ -117,6 +117,15 @@ u64 dma_iommu_get_required_mask(struct device *dev) struct iommu_table *tbl = get_iommu_table_base(dev); u64 mask; + if (dev_is_pci(dev)) { + u64 bypass_mask = dma_direct_get_required_mask(dev); + + if (dma_iommu_dma_supported(dev, bypass_mask)) { + dev_info(dev, "%s: returning bypass mask 0x%llx\n", __func__, bypass_mask); + return bypass_mask; + } + } + if (!tbl) return 0; -- 2.33.0