Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1971498pxb; Mon, 18 Jan 2021 05:06:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJx6P6Y9GSLG3Ttwf1sWd8oF2pZccknmdRsGoCKs3udr/9gb0oiLqbaDm/cKcvqkd7BfoHi6 X-Received: by 2002:a50:fe0e:: with SMTP id f14mr19727081edt.159.1610975192418; Mon, 18 Jan 2021 05:06:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610975192; cv=none; d=google.com; s=arc-20160816; b=fd1ncyOd6i/PghW5tRTZT5utwOLDtK4wEBCZk1f/+VpvaZs6QSPijQffMI5goR/M7h a+NzUgJaiUJ1GgL+WUwlHA0hJODvtjLxSBeYR6gRFG4GJj3UlxjuY2yPtD3d7L7lzrku 3LDf9gcdQwtrkRETFT4XOM7d6mEaiap37+na/+kVJ8EDWyJQFTldct2XzUxK8WSPf3fp czzKeyC154LlpJ6bT4AnifRrdO1dkSFvIM8RFe73alZuaMatagQ/NFTwNt1CWeHs80KC fXJ019sndDoqRRdkWDC4cLnOOSg+Cv5HsBNTwG4OhgLXyum+tyu2sE/vIRPYwiNcwoTv 76HQ== 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=Xs9CAHpNqlw6utyNbFAq1CLzPTEuAWp8DtGwL0riEBE=; b=c5xXGZzQGHZPXRS4ghirn83dk6KzrvlsigiwgOtr2F1jtMX6yTzWXh+FXdrBhGbUEB K/oWLkz9+mkIAm/UN+IzfY2oMnFBMycGLTmfV8NVwxgMQhas5ca4NZXsd74r8x7Whq7H SAal2qqwDSD5ev3vaZDoewr02adWT7XW6OyWEoR8A4iISahq9F7LELUPeNtahXzs0PcW urSPtZweGULpsLLhGo7P62eyewiqwCyEZf6+ByMgyr5P1wu6gAdJp7rCEJXR1kWSFl3f 8oXSlDIioiIPr/N07Ky4WFs63k9ans0yCMU/YrV9409BcPeO+T7CcwjJDGcemRosnI3D ur2g== 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 o60si7966194eda.61.2021.01.18.05.06.08; Mon, 18 Jan 2021 05:06:32 -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 S2391754AbhARNDa (ORCPT + 99 others); Mon, 18 Jan 2021 08:03:30 -0500 Received: from foss.arm.com ([217.140.110.172]:35252 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390332AbhARNAR (ORCPT ); Mon, 18 Jan 2021 08:00:17 -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 52AC731B; Mon, 18 Jan 2021 04:59:31 -0800 (PST) Received: from [10.57.39.58] (unknown [10.57.39.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2E36F3F719; Mon, 18 Jan 2021 04:59:30 -0800 (PST) Subject: Re: [PATCH v4 2/3] iommu/iova: Avoid double-negatives in magazine helpers To: John Garry , Jean-Philippe Brucker Cc: joro@8bytes.org, will@kernel.org, linux-kernel@vger.kernel.org, linuxarm@huawei.com, iommu@lists.linux-foundation.org References: <1607538189-237944-1-git-send-email-john.garry@huawei.com> <1607538189-237944-3-git-send-email-john.garry@huawei.com> <69c30e85-4a72-a0e1-1e56-4ffbd0df5aba@huawei.com> From: Robin Murphy Message-ID: <69614e38-fcc0-4220-e1cd-15de91dd61ef@arm.com> Date: Mon, 18 Jan 2021 12:59:26 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-01-18 10:55, John Garry wrote: > On 18/01/2021 10:08, Jean-Philippe Brucker wrote: >>>> Any idea why that's happening?  This fix seems ok but if we're >>>> expecting >>>> allocation failures for the loaded magazine then we could easily get it >>>> for cpu_rcaches too, and get a similar abort at runtime. >>> It's not specifically that we expect them (allocation failures for the >>> loaded magazine), rather we should make safe against it. >>> >>> So could you be more specific in your concern for the cpu_rcache >>> failure? >>> cpu_rcache magazine assignment comes from this logic. >> If this fails: >> >> drivers/iommu/iova.c:847: rcache->cpu_rcaches = >> __alloc_percpu(sizeof(*cpu_rcache), cache_line_size()); >> >> then we'll get an Oops in __iova_rcache_get(). So if we're making the >> module safer against magazine allocation failure, shouldn't we also >> protect against cpu_rcaches allocation failure? > > Ah, gotcha. So we have the WARN there, but that's not much use as this > would still crash, as you say. > > So maybe we can embed the cpu rcaches in iova_domain struct, to avoid > the separate (failable) cpu rcache allocation. Is that even possible? The size of percpu data isn't known at compile time, so at best it would add ugly runtime complexity to any allocation of a struct iova_domain by itself, but worse than that it means that embedding iova_domain in any other structure becomes completely broken, no? Robin. > Alternatively, we could add NULL checks __iova_rcache_get() et al for > this allocation failure but that's not preferable as it's fastpath. > > Finally so we could pass back an error code from init_iova_rcache() to > its only caller, init_iova_domain(); but that has multiple callers and > would need to be fixed up. > > Not sure which is best or on other options. > > Thanks, > John