Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1230244pxb; Fri, 22 Jan 2021 10:05:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBsqlKyL97i9IaR++lFA1hanndN/NMn5kmJ4psZKxz3g7ewC438Y4cK6T9mE0vJaIre4in X-Received: by 2002:a17:906:e0cd:: with SMTP id gl13mr3950553ejb.17.1611338743827; Fri, 22 Jan 2021 10:05:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611338743; cv=none; d=google.com; s=arc-20160816; b=i1mP/Rw3FXqs8CBmwqayKWZ4QKi76o/3ZzWIp6zOr7DS0yQc1S9qGGDp3PCgDXaQPB KC78NqPwemvZZxz2jn8T5j8k66gsP+Z4F1q7BxAl9g2lncZvlHWY8NIL2+Q8nLgq7NG0 V/JBOjAL2N0v/4JMWe6MTxcqCMhZQfNR3GDMr5KecC4xFS/xELLGoKlWufzXn8UAXAac BPORYRNwG+JwOn59EKVNgPbCgadhA7LBTuBZM0F5ehyWd/Ggp7rsRR5wSKl8j682o6qg ppWpJ6SHPjD/K/etfQ26U1xlanXMWphY/fa0pv5ayrsOrSaW2a57aTzzP3OjbW3ebjUJ fDBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=+6tbIaVmVydfUOxunVkBD+uE/c035INEbGofWx3LmuY=; b=qDizZsKTqKQzjXSu3iytS0Bsuhh1iwcV/B77Qy5JWmBu/q2lTxbJlRC+ahGyK1k1j1 1sn7aMbL9JmNYTCwhfvdUxiKJ27tDHPn5Icg0WE38hQ3bXtZOJKY98kwEZ4TcN5Gyg41 dGIOPDGTbs2yibU7cOMSiuImHZKOmLum1XhJPG3mS9m6VkpWlIXhxo+x98FQxZ7dSSOh s9iWW9ZgvLjk/ZAMpiKEZGB0/oD3UIR/+WLdSqrEOgY2UiUggAV2Ak0w0Iw3KKB7Ere7 jOElx6j7Zwkz9NVXqkUSiEFciGh+eFnfYzGEKJj7vt1DI42WXA+tRr/OY6t2IMUZzNzM Ag7Q== ARC-Authentication-Results: i=1; mx.google.com; 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 t21si608759edq.451.2021.01.22.10.05.18; Fri, 22 Jan 2021 10:05:43 -0800 (PST) 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; 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 S1728644AbhAVSCU (ORCPT + 99 others); Fri, 22 Jan 2021 13:02:20 -0500 Received: from mail-pj1-f46.google.com ([209.85.216.46]:51297 "EHLO mail-pj1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729329AbhAVRvb (ORCPT ); Fri, 22 Jan 2021 12:51:31 -0500 Received: by mail-pj1-f46.google.com with SMTP id a20so1302835pjs.1; Fri, 22 Jan 2021 09:51:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+6tbIaVmVydfUOxunVkBD+uE/c035INEbGofWx3LmuY=; b=nMgdO6SpY1bs3Es22hg5/01h/eWcidW4nlHMu0lud3swVE4eHYkUNJ8P3CttrmLYu1 lpoB/bnN6CrNNAmESLKEZZu6/Og08wr2uasx7GUFhqnNEMPS3KwuMfu08tIiXFT3db8z EGk4OO5j4WWGRiBxi0LI9TZR5N3FI1eO5LPuY/5rcYPTlf/1KACP6f/NDxE+47t+YwfW t2xfYsh2cGq9vAPdSYlV0kohYaWSpGMy3UoP95YOIfdVaBg4mGiUToz0gOiqrLiclILt XkO04h/r6LxGZLGkGBt32T3SfaTajZMdo1JeIgWpn8UVulMlbj+t/tUi+76RWCJm81Qy e4KA== X-Gm-Message-State: AOAM532BszS/iPXCCwEbPMJFMqEqgM/QobT3RLzjLV7b/YrfH6qf9LTB u1xGReBp87d4oCDSCMueKzs= X-Received: by 2002:a17:90b:1a87:: with SMTP id ng7mr6889308pjb.211.1611337845501; Fri, 22 Jan 2021 09:50:45 -0800 (PST) Received: from localhost ([2601:647:5b00:1162:1ac0:17a6:4cc6:d1ef]) by smtp.gmail.com with ESMTPSA id j6sm9362292pfg.159.2021.01.22.09.50.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 09:50:43 -0800 (PST) Date: Fri, 22 Jan 2021 09:50:40 -0800 From: Moritz Fischer To: Robin Murphy Cc: Moritz Fischer , lorenzo.pieralisi@arm.com, guohanjun@huawei.com, rjw@rjwysocki.net, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, moritzf@google.com, sudeep.holla@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v2] ACPI/IORT: Do not blindly trust DMA masks from firmware Message-ID: References: <20210122012419.95010-1-mdf@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Robin, On Fri, Jan 22, 2021 at 02:42:05PM +0000, Robin Murphy wrote: > On 2021-01-22 01:24, Moritz Fischer wrote: > > Address issue observed on real world system with suboptimal IORT table > > where DMA masks of PCI devices would get set to 0 as result. > > > > iort_dma_setup() would query the root complex'/named component IORT > > entry for a DMA mask, and use that over the one the device has been > > configured with earlier. > > > > Ideally we want to use the minimum mask of what the IORT contains for > > the root complex and what the device was configured with. > > > > Fixes: 5ac65e8c8941 ("ACPI/IORT: Support address size limit for root complexes") > > Signed-off-by: Moritz Fischer > > --- > > > > Changes from v1: > > - Changed warning to FW_BUG > > - Warn for both Named Component or Root Complex > > - Replaced min_not_zero() with min() > > > > --- > > drivers/acpi/arm64/iort.c | 14 ++++++++++++-- > > 1 file changed, 12 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c > > index d4eac6d7e9fb..2494138a6905 100644 > > --- a/drivers/acpi/arm64/iort.c > > +++ b/drivers/acpi/arm64/iort.c > > @@ -1107,6 +1107,11 @@ static int nc_dma_get_range(struct device *dev, u64 *size) > > ncomp = (struct acpi_iort_named_component *)node->node_data; > > + if (!ncomp->memory_address_limit) { > > + pr_warn(FW_BUG "Named component missing memory address limit\n"); > > + return -EINVAL; > > + } > > + > > *size = ncomp->memory_address_limit >= 64 ? U64_MAX : > > 1ULL<memory_address_limit; > > @@ -1126,6 +1131,11 @@ static int rc_dma_get_range(struct device *dev, u64 *size) > > rc = (struct acpi_iort_root_complex *)node->node_data; > > + if (!rc->memory_address_limit) { > > + pr_warn(FW_BUG "Root complex missing memory address limit\n"); > > + return -EINVAL; > > + } > > + > > *size = rc->memory_address_limit >= 64 ? U64_MAX : > > 1ULL<memory_address_limit; > > @@ -1173,8 +1183,8 @@ void iort_dma_setup(struct device *dev, u64 *dma_addr, u64 *dma_size) > > end = dmaaddr + size - 1; > > mask = DMA_BIT_MASK(ilog2(end) + 1); > > dev->bus_dma_limit = end; > > - dev->coherent_dma_mask = mask; > > - *dev->dma_mask = mask; > > + dev->coherent_dma_mask = min(dev->coherent_dma_mask, mask); > > + *dev->dma_mask = min(*dev->dma_mask, mask); > > Oops, I got so distracted by the "not_zero" aspect in v1 that I ended up > thinking purely about smaller-than-default masks, but of course this *does* > matter the other way round. And it is what we've always done on the DT side, > so at least it makes us consistent. > > FWIW I've already started writing up a patch to kill off this bit entirely, > but either way we still can't meaningfully interpret a supposed DMA limit of > 0 bits in a table describing DMA-capable devices, so for this patch as a > fix, > > Reviewed-by: Robin Murphy I think there's another issue the comparisons for revision should be against < 2 not < 1. From what I could find DEN0049D (IORT) spec introduced the fields (curiously the C doc seems to be missing). DEN0049B specifies revision as '0', DEN0049C (missing?), DEN0049D specifies new fields for memory_size_limit and both Named Component and Root Complex nodes set revision to 2. so I think it should be: if (!node || node->revision < 2) return -ENODEV; Only if we go past this and there is no address limit is it really a firmware bug. > > Thanks, > Robin. > > > } > > *dma_addr = dmaaddr; > > - Moritz