Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp436680pxt; Thu, 5 Aug 2021 03:29:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/iWj92huSswIwGC+E4Kk4mEaQVHGITM8oJKgE5vVAFwNohRA4bNw3a2A7AVuCC9LE7M5Z X-Received: by 2002:a17:906:a98e:: with SMTP id jr14mr4107512ejb.450.1628159342533; Thu, 05 Aug 2021 03:29:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628159342; cv=none; d=google.com; s=arc-20160816; b=KRhM7mXFZvQWECxE07q9VxtTJKFjMfnIHMMl+LQtMEv0g2yc1/YxGB0PwuVdXkALSx B7khMrt5uFTQTnFYGBrVWXXTNGNcNvSPz+OTlONQlLCcMgR3IBOzL7DUDq91IaK+nMMR h/NIw3+QI1j/lkbZVNyzoW0E9eTwoPtmy20meqWHqIwzRq112XaXC/pfGt4YbWQrfOk1 UsQ5DJIJwuV2vXS2CajfHuN1QvtgeHD5kq9krNb+StZ2HbtlL+FIPPeOlktm/U0AUfrG Dt4wybRTd5vIv8C79uUjj9woTSvxMdoNMkaghzXbn5b23xmj7XmwAp6b92I1QjKfYwF4 dA0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=5BGolqoyUNapArEqal6Ms+g6sLmdw2mR4RY07/et2IA=; b=q/Th8IT9PaSdia0GhyjvHRz4NlDS80gaOl3EGwSLYSWOelejsDw1Vd+cBSpEaoER7d 0ta/iPhYMS/886W8QuVRMFcdSQSjeOwahvpBSYKzNejnIDGIR9N3fZTggHLEuS9DOaDq fphMlKCA/Ir/S/hRXJF4MR535qADutaBNZS1VJcL+LBH5HnK0lpRnz5RY2DFpw1gRj2W GvDVPOLmjQl1+W09TQKp828ND0+6bSoKHhipwuA+Cd8iv8FMlgxgNoln8YTWRZf33Ja8 acTgZaiKRA6uKB0Z4e3HHwAO+qnYXqIKDhs2SoSNSQIOJrY7JKNrgJdvYiKWLWhJlniD icCA== 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i8si6490666ejj.636.2021.08.05.03.28.29; Thu, 05 Aug 2021 03:29:02 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240337AbhHEK0g (ORCPT + 99 others); Thu, 5 Aug 2021 06:26:36 -0400 Received: from foss.arm.com ([217.140.110.172]:42446 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239963AbhHEK0f (ORCPT ); Thu, 5 Aug 2021 06:26:35 -0400 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 BEB591FB; Thu, 5 Aug 2021 03:26:21 -0700 (PDT) Received: from [10.57.36.146] (unknown [10.57.36.146]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9178A3F719; Thu, 5 Aug 2021 03:26:20 -0700 (PDT) Subject: Re: [PATCH] of: restricted dma: Don't fail device probe on rmem init failure To: Will Deacon , linux-kernel@vger.kernel.org Cc: iommu@lists.linux-foundation.org, Claire Chang , Konrad Rzeszutek Wilk , Christoph Hellwig , Rob Herring References: <20210805094736.902-1-will@kernel.org> From: Robin Murphy Message-ID: Date: Thu, 5 Aug 2021 11:26:15 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210805094736.902-1-will@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-08-05 10:47, Will Deacon wrote: > If CONFIG_DMA_RESTRICTED_POOL=n then probing a device with a reference > to a "restricted-dma-pool" will fail with a reasonably cryptic error: > > | pci-host-generic: probe of 10000.pci failed with error -22 > > Print a more helpful message in this case and try to continue probing > the device as we do if the kernel doesn't have the restricted DMA patches > applied or either CONFIG_OF_ADDRESS or CONFIG_HAS_DMA =n. Makes sense to me; Reviewed-by: Robin Murphy Although if we allow probe to succeed when a pool really was there for a reason, it may end up being much more fatal if the driver then tries to do a DMA transfer to any old memory and the device access causes an SError, or the VM to be killed, or whatever. That's not quite the same as the stubbed cases where the respective platforms couldn't have a genuine pool to parse either way, but as you say it is what could happen already if the user tried to use an older kernel, and I think the chance of of_reserved_mem_device_init_by_idx() failing without something being terminally wrong anyway - invalid DT, not enough RAM, etc. - is low enough that it's probably not a major concern. Plus I'd hope that the memory protection schemes people do actually implement don't take such such a zero-tolerance approach anyway - allowing a malicious or malfunctioning device to take down the system because it tried to make a rogue access which *was* already contained seems a bit silly. Robin. > Cc: Claire Chang > Cc: Konrad Rzeszutek Wilk > Cc: Robin Murphy > Cc: Christoph Hellwig > Cc: Rob Herring > Signed-off-by: Will Deacon > --- > drivers/of/address.c | 8 ++++---- > drivers/of/device.c | 2 +- > drivers/of/of_private.h | 8 +++----- > 3 files changed, 8 insertions(+), 10 deletions(-) > > diff --git a/drivers/of/address.c b/drivers/of/address.c > index 973257434398..f6bf4b423c2a 100644 > --- a/drivers/of/address.c > +++ b/drivers/of/address.c > @@ -997,7 +997,7 @@ int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map) > return ret; > } > > -int of_dma_set_restricted_buffer(struct device *dev, struct device_node *np) > +void of_dma_set_restricted_buffer(struct device *dev, struct device_node *np) > { > struct device_node *node, *of_node = dev->of_node; > int count, i; > @@ -1022,11 +1022,11 @@ int of_dma_set_restricted_buffer(struct device *dev, struct device_node *np) > */ > if (of_device_is_compatible(node, "restricted-dma-pool") && > of_device_is_available(node)) > - return of_reserved_mem_device_init_by_idx(dev, of_node, > - i); > + break; > } > > - return 0; > + if (i != count && of_reserved_mem_device_init_by_idx(dev, of_node, i)) > + dev_warn(dev, "failed to initialise \"restricted-dma-pool\" memory node\n"); > } > #endif /* CONFIG_HAS_DMA */ > > diff --git a/drivers/of/device.c b/drivers/of/device.c > index 2defdca418ec..258a2b099410 100644 > --- a/drivers/of/device.c > +++ b/drivers/of/device.c > @@ -166,7 +166,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, > arch_setup_dma_ops(dev, dma_start, size, iommu, coherent); > > if (!iommu) > - return of_dma_set_restricted_buffer(dev, np); > + of_dma_set_restricted_buffer(dev, np); > > return 0; > } > diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h > index f557bd22b0cf..bc883f69496b 100644 > --- a/drivers/of/of_private.h > +++ b/drivers/of/of_private.h > @@ -163,18 +163,16 @@ struct bus_dma_region; > #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_HAS_DMA) > int of_dma_get_range(struct device_node *np, > const struct bus_dma_region **map); > -int of_dma_set_restricted_buffer(struct device *dev, struct device_node *np); > +void of_dma_set_restricted_buffer(struct device *dev, struct device_node *np); > #else > static inline int of_dma_get_range(struct device_node *np, > const struct bus_dma_region **map) > { > return -ENODEV; > } > -static inline int of_dma_set_restricted_buffer(struct device *dev, > - struct device_node *np) > +static inline void of_dma_set_restricted_buffer(struct device *dev, > + struct device_node *np) > { > - /* Do nothing, successfully. */ > - return 0; > } > #endif > >