Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2065374pxb; Mon, 18 Jan 2021 07:23:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJz35chRi2qrvaGU691TFm9+V0gS90F3gClk6PyKG0kuqmHChQEeHsFHqn8BwN0kuE/G2qHV X-Received: by 2002:a17:907:3e06:: with SMTP id hp6mr155824ejc.254.1610983382570; Mon, 18 Jan 2021 07:23:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610983382; cv=none; d=google.com; s=arc-20160816; b=FIeNkl/Xwic5CzAWAYVl2aSeaumfyg8sjvd5sCeg9wUD2ieBuDYr+T6+ygz0u5Y6lS 7mA2iUqrtlcrJegndq7t4kBgruNjf2U44rnJx8ul9eGSsSSpSNTpGtYVRjrz0vFZP0Or 1AYY+mLYqZ1aZQTemtsnpyvoRqV2jMUHHJ8pOLp+816fp35+8m1keyHzejUmzVSDgPlB q9GXkFfpCXDza+jfYyhNuGcXgvLaOcjRfEg50tOfxShD6PVKVFgxG1fj/w5yrycoJ748 9JCEHSCmX2lP3o9aFQqO8Bth+8OakHMOto9l/ycKH+h7X/C6G3/owhml84FgKian1OT0 uMTQ== 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=Gt/azYMAlN0Q5YCC27Q/7X0DwUX/fvE96wWSoH/1/Qc=; b=JJD8ds30TnDFEWyCf4w0TaGXQGkUTMB4PPvA8osWWzhXgewMUaArU/b1zUmVK/XpE2 9WFxDjySPDJbjcee6Jma2Z0K1dUymm5FMmu3efpIAdD4th76PhXC5In8AVu+I1MzXvwH AaKZknTCXGcj7oFeBaJZbhMCMwEotEWE8jZxuu16hJEpLwd/BUiuzpEIEqCmBVnzoWnx 2PFNpaygSC+POhr6l5lE9pOxlzPWo/85MpaWpLVFNFIbg+K2toTkiLiA9ly/VaLcEx/R /d2fSSb+PMtjHtVUyPCZ7Rwqa28WzVSq3n5LelxbeV5j7bI9aEIYbeV2xTnly80MhFE4 jvFQ== 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 p18si2777883edx.449.2021.01.18.07.22.38; Mon, 18 Jan 2021 07:23:02 -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 S2405694AbhARPTV (ORCPT + 99 others); Mon, 18 Jan 2021 10:19:21 -0500 Received: from frasgout.his.huawei.com ([185.176.79.56]:2367 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405477AbhARPLu (ORCPT ); Mon, 18 Jan 2021 10:11:50 -0500 Received: from fraeml741-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4DKFW45rLFz67bgN; Mon, 18 Jan 2021 23:06:56 +0800 (CST) Received: from lhreml724-chm.china.huawei.com (10.201.108.75) by fraeml741-chm.china.huawei.com (10.206.15.222) 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 16:11:01 +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 15:11:00 +0000 Subject: Re: [PATCH v4 2/3] iommu/iova: Avoid double-negatives in magazine helpers To: Robin Murphy , 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> <69614e38-fcc0-4220-e1cd-15de91dd61ef@arm.com> From: John Garry Message-ID: <5fdeed73-190f-3272-03e5-8adc60148521@huawei.com> Date: Mon, 18 Jan 2021 15:09:47 +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: <69614e38-fcc0-4220-e1cd-15de91dd61ef@arm.com> 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 12:59, Robin Murphy wrote: >>>>> 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? Ah, now I see that it's not possible. I was thinking of using DEFINE_PER_CPU(), but it's not permitted. So even though this patch saves us from cpu_rcache->loaded / ->prev == NULL, I still prefer not to add explicit checks for cpu_rcache == NULL in the IOVA alloc/free paths, and would rather pass an error back in init_iova_rcaches(), but adding code for tidy-up looks messy. Thanks, John