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=-14.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 1FA8DC433DB for ; Fri, 22 Jan 2021 19:45:13 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 D9F5623AF8 for ; Fri, 22 Jan 2021 19:45:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D9F5623AF8 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+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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6ISyW5+Hs7p32id7c+WPpy6T996w1mVMf4z4vHORfUg=; b=vcS7uOlkHJC3VehvSGDjtXaPy 3crNt4+EsuAe4WWwgBzYRe/TE9GQ0unlzAzwe/gwMdTAUx+zrI6tDU/illkrrc3XEyLUR0Br1vSdq 20/wnyw4N70qzAuGc3IB8cQUe0brxHeOJz+BjvmQGCusf30JscmIY9h/vUg2G6DKqFwxG3BmhE9gk ufgGUKKtHGcMpZmYy9DhVYXRlwegzuCB8EIBqiI7fRiLbCdejwdCMAGu74h3gFsA5aP4P4WWKF3T4 Gj8TghOR6ZQxytZM0Im9M7acBV80PyY5Qw47bQwzupzdU/aqlYZtH4jOHU270grijkZj6hPJAoXqb CAWoVmI0w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l32LT-0003B9-IH; Fri, 22 Jan 2021 19:43:47 +0000 Received: from mail-pg1-f180.google.com ([209.85.215.180]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l32LQ-0003AQ-Lk for linux-arm-kernel@lists.infradead.org; Fri, 22 Jan 2021 19:43:45 +0000 Received: by mail-pg1-f180.google.com with SMTP id n25so4533261pgb.0 for ; Fri, 22 Jan 2021 11:43:40 -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=ATG0GXwb6cHOMUq0Deoow7zIfUyiL9nWB+7HYnwDTXA=; b=oUdLDyVFJkE0gNcNNfMRdVgsotMXUlN+xXtQJDW4N50cYsWOVUuGJBh7uD/uvZxQS+ v7KaFIyK2zxof2uNJLhEv0IS9lqkWsnGBgsROfw72IArP79fyauNtaOMFWFNeUo0AA9U xBRNKWL/4VXwoHjYyeTEnlgLmEV8tVkAde9tRr4ZzbYG5fu3+Ap7pmoY8dkqwfqK3qBi XfUpMoeuPOKNe/FDR1fihSMTN9uKFsFy7QAXBg+ReuZYuSdnmYwqdRP95B9ETKXeM3sZ w6zMT4p2SWo1DOwOdZcKP61KZ2fN+3aUs+yyiPK3oef9HZzrHDgN/lqO0ngch6p7xDWf yjyw== X-Gm-Message-State: AOAM5305AGt2iroKvStQ3VUaXtWqVClWEgM2oM5JFLnxCW+9XHIh55iv mHBBprNS/US6hbEyaiSFno4O9hThG2lr2Q== X-Google-Smtp-Source: ABdhPJxYQr1Ch6qIKOrEYXGLMhs510aFr2+YqABRUXxW3HRV5y/SFkvSXB7CqcVBI21jxE2gabFISw== X-Received: by 2002:a62:cf02:0:b029:1a4:6899:618e with SMTP id b2-20020a62cf020000b02901a46899618emr1068870pfg.70.1611344620089; Fri, 22 Jan 2021 11:43:40 -0800 (PST) Received: from localhost ([2601:647:5b00:1162:1ac0:17a6:4cc6:d1ef]) by smtp.gmail.com with ESMTPSA id i62sm6223677pfe.84.2021.01.22.11.43.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 11:43:38 -0800 (PST) Date: Fri, 22 Jan 2021 11:43:37 -0800 From: Moritz Fischer To: Robin Murphy Subject: Re: [PATCH v2] ACPI/IORT: Do not blindly trust DMA masks from firmware Message-ID: References: <20210122012419.95010-1-mdf@kernel.org> <29575ef5-a1c1-16d7-5fed-7fc34d772a7a@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <29575ef5-a1c1-16d7-5fed-7fc34d772a7a@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210122_144344_716133_C090271F X-CRM114-Status: GOOD ( 38.69 ) 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: lorenzo.pieralisi@arm.com, sudeep.holla@arm.com, rjw@rjwysocki.net, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Moritz Fischer , moritzf@google.com, guohanjun@huawei.com, will@kernel.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Jan 22, 2021 at 07:17:59PM +0000, Robin Murphy wrote: > On 2021-01-22 17:50, Moritz Fischer wrote: > > 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). > > I guess it got lost in the documentation system move. FWIW I still have a > copy of issue C, and root complex nodes are unchanged at revision 0 there. > > > 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. > > My copy of issue D says Root Complex nodes are at revision 1, with memory > address size limit added. > > (Note that Named Component nodes did bump to rev. 1 in issue C, then to rev. > 2 in issue D) > > Issue E bumped Root Complex nodes to revision 2 with the addition of the PRI > flag, then E.a made a mess of everything by deprecating the revision numbers > for individual tables - we probably need to deal with *that*, since > otherwise we'll think new tables are back at rev. 0 again, but AFAICS the > current check is correct for anything written against the first 5 releases. Ok, yeah, I double checked this, you're right. Then patch should be fine as is. Thanks! _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel