Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2456748pxb; Mon, 18 Jan 2021 19:46:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJzx8RoyPpHZaSBGp2hW1HWbRdfV5rd6p7aWMZZZF2/D8wBSXt8kuK5twWwgu1KLFnaDhzzw X-Received: by 2002:aa7:c3d3:: with SMTP id l19mr1898115edr.366.1611027976704; Mon, 18 Jan 2021 19:46:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611027976; cv=none; d=google.com; s=arc-20160816; b=hF5zV+6xIEku5R6FSX5zxSnUUayDGisvzDX79wzRSv6oN32WqFUfElrTLspj2EI70C 8rjtW4QN7stRDAByAQXDNn7GY9455TXIIxYuCE0/myOHG3eOAOLZBpkHO5Q+m46gdFb5 7RrSM+emp6XKjI9wdP/edZ3heV5JDCZCJNfP4hcD/Kbth5jtKdkfzn05c+AnpJrjdkrF C19huKgXBY3xIpPxThq1t328yGBGwIkhpkqZgYTe0g1S1TBo1fvgz8q7u3thPEUC5nTF lEsdciLgI7j4qYxlbdkJltHIDQKy5D9i4nlsch7N+2lTYTtXghL35WeICj8jRTUt1fwi AQgw== 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=SjRzdW0rnfimYaUssOg6DRJGsLvRwdmILT6wtUpJ/P0=; b=Xxu6G8XVULDsLQBOORUwt0IHKHpunTTtztS0VnRmaoQU1rCQaD1F63DDoHOkNzMPpB aH5VC7iPUZUvAEo6wqGrA27KwATMMMy1LJPjCk0kA3Qq4DIIgHuI/bh30JX/uZLC+ISc vcngXa8xfZNzgBN8bqATfMevx5jcR/YajkCYaCHNc80n5sOKAVMSv8lFUSGu/abRLjl6 O+i08ScOkcfbdmuw1ZBOoXYk00goNPQHF0Gf5Ha5aLiE1axvzt7at2CI8v/kkpwCuQ/9 XKg6/oNmGxOFHY/g8+K5vlRgh4/q83g+Qwwt95o8eioVev3x9hSOuUEgDPUkkGWpk0Yi OTXw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g13si8354066edk.250.2021.01.18.19.45.50; Mon, 18 Jan 2021 19:46:16 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388915AbhARK6s (ORCPT + 99 others); Mon, 18 Jan 2021 05:58:48 -0500 Received: from frasgout.his.huawei.com ([185.176.79.56]:2363 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389685AbhARK56 (ORCPT ); Mon, 18 Jan 2021 05:57:58 -0500 Received: from fraeml738-chm.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4DK7vC4YwQz67d8r; Mon, 18 Jan 2021 18:53:59 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml738-chm.china.huawei.com (10.206.15.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Mon, 18 Jan 2021 11:57:05 +0100 Received: from [10.47.8.82] (10.47.8.82) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Mon, 18 Jan 2021 10:57:04 +0000 Subject: Re: [PATCH v4 2/3] iommu/iova: Avoid double-negatives in magazine helpers To: Jean-Philippe Brucker CC: , , , , , 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: John Garry Message-ID: Date: Mon, 18 Jan 2021 10:55:52 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.47.8.82] X-ClientProxiedBy: lhreml744-chm.china.huawei.com (10.201.108.194) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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