Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp441376pxb; Fri, 8 Jan 2021 08:48:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJw3C2Bwjcg7S+JlTUe2WJPLuIvUFfOMpto2MgQjnQHC56wPSnUALTMUlyhql3FZtC+1F6s8 X-Received: by 2002:a17:906:1151:: with SMTP id i17mr3317382eja.250.1610124506664; Fri, 08 Jan 2021 08:48:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610124506; cv=none; d=google.com; s=arc-20160816; b=RWz+Vv0Q8szaTl6aJhgcBvSifKEYSRhzDbBIApPaEpK/OTvFvA2MtlQ3s/TesE3dup kh2DQP3LPZ0/UCuEzqTQj/obCj0M38tlhGvyjvM8aFHX9iW4WRUddwbJSbJ2zSqwNlDB sC5GLN6ATHMAGOriWucSf2uk5h6JR9diR1IE7RmykK2ufA1/YrKfofcF+ElKEuRqC2Ex 1xlALhPSDjS2gn2j3VWVRicEGKd9ttovCQwm8T0ngTlDKLvqTzYrvkZIiOzRz2++hBXk k7/K7iCOf7tJiA5TSaTUDp+F5dQgClueBN/0Q4W5b+lZuZRVomee7U+lyQm9Qo0Kcpeu V3IA== 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:dkim-signature; bh=MG354YKqeHyUgNMxgEUcLfyaw4nS+tNiKDhutFtITdM=; b=0DZ2XqNQvE4LH8daBZb08MwRz+kaluHM0qEVeuxLp/x8c7qEtj8DuxnUZ1iV49tHUe xSiUi9HA2wXWkwagfEHp1dfeakVkdPTDRmjEqPc7bDowK/rFIerAw6pKellRQS4sh+JN V8abVx4Sc473XEseAAFnxx7sVN1UW/Tl0uYoVk1lF6z35AqoTrflADWffOqLZSAe9H64 BJ1BUVTXppEPkcoBzysy3Z2T7CBHz4XwTAobqLdMLS8PoN2YoUiGTS8vpMbIzW0ZS2XX OjSrxBFD3H0Dc1WXX8wUiz8JB7Lx6nmFiUY7tBrIBoj+gxbWETXRk0V7wuXtl485HoHV +bRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lyrXu56q; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m8si3552036ejr.206.2021.01.08.08.48.02; Fri, 08 Jan 2021 08:48:26 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lyrXu56q; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728082AbhAHQpv (ORCPT + 99 others); Fri, 8 Jan 2021 11:45:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728068AbhAHQpv (ORCPT ); Fri, 8 Jan 2021 11:45:51 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DCF3C0612EA for ; Fri, 8 Jan 2021 08:45:11 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id t16so9648373wra.3 for ; Fri, 08 Jan 2021 08:45:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=MG354YKqeHyUgNMxgEUcLfyaw4nS+tNiKDhutFtITdM=; b=lyrXu56qrmAzlKwKP703dHpcw9vR0LK7NuBeN+mVDSUwHciK8SqHbgGhSAJvPt0uP3 gSNZttsPCUOHi+gebWpE6BiQW5oO5ifJFxV20x/F6+cXBf0q1wi2fBAzcYG8R0+fFfTL 64v4riw2Co/e8UAxyfQPCpdDDnaV9ALjAFB2tQiyk6kQ3wstg8FwvV/tw6nrt5k6wT8V 0tnkiGSYzx8OjbJt1ZDQpMSDZAGjduUQsYmOgtOT8qwku8Ll9ZfocmnVLp+4w50Ej6LT gko1/W9ueD17eU36zGWjYl80ClJRm/hxavo3kgTkOoOHhbSWXahdFXVj4TtGwamJNf+p uvpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=MG354YKqeHyUgNMxgEUcLfyaw4nS+tNiKDhutFtITdM=; b=gjQH+N5hOQux5q/MLmIZPzxYfTLkWIwiybw2RKd9cYY3wBmXFTvt6tvZNi5l/pHYjb XuDUOTmIpk7vuVGOnyzY8lUpSMyoMDT8+wCKyHdh16AQDeH2py3CWT7RAXhdb0+jQif0 9NowPIZCqGtFuJXJvBRHNbCzWUIY1p5M0OKoVGxfCrlSHzkJAACwpWmFOYLpEOJ4ONuQ StiBc9tdr+m7rgBOtSN09bIW+TPkUxVGzpXqiz2MRmeQF2ABk8LPSYwT15/k+NdFIl/L UHJkt+n3rahLc71+FqvQ9xgQV0EhHZpWH1B46mRdKY7B/Qc0HJ25emwC4BzM3xj4ieDC bB5Q== X-Gm-Message-State: AOAM532YwKDwgYVal6jVn1hKfh49573wky75t0kOpmZ1FRYmq1pjN3bh wIaCofbD5mjl3Rs9CeKLtlYN1F6faSQ= X-Received: by 2002:adf:fdce:: with SMTP id i14mr4577268wrs.58.1610124309479; Fri, 08 Jan 2021 08:45:09 -0800 (PST) Received: from ?IPv6:2003:ea:8f06:5500:6dbb:aa76:4e1a:5cc4? (p200300ea8f0655006dbbaa764e1a5cc4.dip0.t-ipconnect.de. [2003:ea:8f06:5500:6dbb:aa76:4e1a:5cc4]) by smtp.googlemail.com with ESMTPSA id g78sm12178501wme.33.2021.01.08.08.45.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 Jan 2021 08:45:08 -0800 (PST) Subject: Re: [PATCH v2] dma-mapping: add unlikely hint for error path in dma_mapping_error To: Robin Murphy , 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: Heiner Kallweit Message-ID: <9cd308a1-2222-8716-2002-c0dacfaa6d91@gmail.com> Date: Fri, 8 Jan 2021 17:45:05 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14.12.2020 14:01, Robin Murphy wrote: > 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; >> Is this patch going to make it to linux-next?