Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2613176pxu; Mon, 14 Dec 2020 06:54:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJzmYfyE4SM0upQHQuJoV1bwivIbu2ohrr278UiTnumM0c6FvHeVvyckTpSFeMp6qdJCj/ob X-Received: by 2002:a17:906:4e52:: with SMTP id g18mr23445437ejw.385.1607957648915; Mon, 14 Dec 2020 06:54:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607957648; cv=none; d=google.com; s=arc-20160816; b=nxEth3QIIVgXvEFSHToBhsI9h1vufvcpZVNMjOo5Phbmg+X2n0hMfOjn1qNwliSL9P VvrgN+MBa4KsuIvQLHEv2TW5UIs0n1pSZDBQptrg7nbkaG5o1+XvMoudYcULYzjBqrt0 YFF9eLJpK8vRXfC8BL/RKWKP3uX8xxml/HSYkovcpt6YGd4EIUgLNS/2dfOrX7DeumW6 9tmYPrZwJgjdZnl+QgBi2yLckOqPLLxiN4mUrE+FlKOaVKJMloeBvqkeo3OQX90F1A2s A1xSkellk83gdF5EN7PKdqTzeTZ4DJDYtHVFth/hzSEKAdzVpS0s7mqLUKD6dDV0ZwC+ mATQ== 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=iQ+E1v/K4l539P1KISPeHi0uaZQYaQW2m22DXBspNWo=; b=r09g2iYdVb5KoRuUIB4xUjf2ZpFhekToKXXkUdcypzS7uS4DjenFRw3YSKuom3yiUA eq8iL3hY3665vz2w9SJUPJivkmloa+wOoXMsneK0wM3pA/+sVJJx+4IZZDhRnPbeZyA/ JIqV6eHjaSgh0pBbw7WCD+AQve9xHBboLQ4PFarKDQQISLpo2RNo6zjtreKyDM8pI/Gf sfCK4gLS3qfQ1s2gdv4m7mI0/werzXlPfCX/irF5ttnrnpQA81q9bYBzIRw3x3GPshWZ dK7GZeOPa/wKGcZU/fwMmxNcyxIRCmWNsQOV4y8O9z70NDui5HcZW2H/Fsz1qmW8gVVU j3KA== 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 c20si12426387ejr.339.2020.12.14.06.53.46; Mon, 14 Dec 2020 06:54:08 -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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407911AbgLNNCR (ORCPT + 99 others); Mon, 14 Dec 2020 08:02:17 -0500 Received: from foss.arm.com ([217.140.110.172]:47166 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407907AbgLNNCO (ORCPT ); Mon, 14 Dec 2020 08:02:14 -0500 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 092FF1FB; Mon, 14 Dec 2020 05:01:28 -0800 (PST) Received: from [10.57.33.60] (unknown [10.57.33.60]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id DE7313F66B; Mon, 14 Dec 2020 05:01:26 -0800 (PST) Subject: Re: [PATCH v2] dma-mapping: add unlikely hint for error path in dma_mapping_error To: Heiner Kallweit , Christoph Hellwig , Marek Szyprowski , Barry Song Cc: "open list:AMD IOMMU (AMD-VI)" , Linux Kernel Mailing List References: <39581f9a-0066-ad98-094d-d41082145e23@gmail.com> From: Robin Murphy Message-ID: Date: Mon, 14 Dec 2020 13:01:25 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.5.1 MIME-Version: 1.0 In-Reply-To: <39581f9a-0066-ad98-094d-d41082145e23@gmail.com> 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 2020-12-13 16:32, Heiner Kallweit wrote: > Zillions of drivers use the unlikely() hint when checking the result of > dma_mapping_error(). This is an inline function anyway, so we can move > the hint into this function and remove it from drivers. Reviewed-by: Robin Murphy FWIW I consider this case similar to the same hint in WARN_ON() and friends - it's a pretty severe condition that should never be expected to be hit in normal operation, so it's entirely logical for it to be implicitly unlikely. I struggle to imagine any case that would specifically *not* want that (or worse, want to hint it as likely). Some DMA API backends may spend considerable time trying as hard as possible to make a mapping work before eventually admitting defeat, so the idea of ever trying to optimise at the driver level for failure in hot paths just makes no sense. Thanks, Robin. > Signed-off-by: Heiner Kallweit > --- > v2: > Split the big patch into the change for dma-mapping.h and follow-up > patches per subsystem that will go through the trees of the respective > maintainers. > --- > include/linux/dma-mapping.h | 2 +- > kernel/dma/map_benchmark.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h > index 2e49996a8..6177e20b5 100644 > --- a/include/linux/dma-mapping.h > +++ b/include/linux/dma-mapping.h > @@ -95,7 +95,7 @@ static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr) > { > debug_dma_mapping_error(dev, dma_addr); > > - if (dma_addr == DMA_MAPPING_ERROR) > + if (unlikely(dma_addr == DMA_MAPPING_ERROR)) > return -ENOMEM; > return 0; > } > diff --git a/kernel/dma/map_benchmark.c b/kernel/dma/map_benchmark.c > index b1496e744..901420a5d 100644 > --- a/kernel/dma/map_benchmark.c > +++ b/kernel/dma/map_benchmark.c > @@ -78,7 +78,7 @@ static int map_benchmark_thread(void *data) > > map_stime = ktime_get(); > dma_addr = dma_map_single(map->dev, buf, PAGE_SIZE, map->dir); > - if (unlikely(dma_mapping_error(map->dev, dma_addr))) { > + if (dma_mapping_error(map->dev, dma_addr)) { > pr_err("dma_map_single failed on %s\n", > dev_name(map->dev)); > ret = -ENOMEM; >