Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1961474pxb; Mon, 18 Jan 2021 04:49:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJxBxB4FTKVKmrLcL7OBTxpN2uCVWTKvvQTxapITCJNcPC0+sxv/GMN/vh0ZyrMRIRVP3Fkf X-Received: by 2002:a50:852a:: with SMTP id 39mr4080842edr.114.1610974156134; Mon, 18 Jan 2021 04:49:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610974156; cv=none; d=google.com; s=arc-20160816; b=rlJHPI6FEEGOkO33fDqK3NGDAoh/BnQW4bCC5OUPhGmuwSlguoRsqrjgo0bt2XOrw0 Ax+RKWJ19VxREQ75kiwZTzm3x/XNRamP9yhsmEusIFvrW1wRHoFp1CA6okDNyk+gGbGP pjix1c6AimodqHyTln77u2J/b00X8M8M0JxLMuSrBJJWJCOBxqgN8+KfpuC5teO4cQ18 IDlUBKlMCt9Virmew/W5rVk4HI+0UvM+VgG8gWYFZoSkqJt1wyQU9bMBUI+O71psC6qq 7iy8JNmybWhG1N+D9+KHfGkAslTK3uomf2M/7jucnt9O5atjB4LSh4ypCYe3uXQGloQe cl4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pUBLkn8FySf4zUY7MqtXXjbLm3L09Eo0TSDMqMBMKfM=; b=CL2xOi+5zw2TthmUoZHDM80gs2fxqUcFaAH6sKfRQV7AnyAs7YcritPtcZvwuVmLOH +9lHJrr9KL/pK+MiUCJ8znWroEiAq+cVQxaLUkliN/W9qtSxyBEkYym4cCkpBViRSUa5 wZ//MER1keeyfC3n/Y3p2E9OSYbtq+bUg1REpYZ0jBzk23Sb1IgN764Ccyovo+IHuNUk /KQcnCdNtJK8fABWTBo3gm2aBxMRIAmcqBZ910bfRio+LlhTJkjiJ+2TXNWaq+1J7sMQ lyNLcDP0/FK0ZB4aXKBeUK3OniD21gUZLLZ7LcD+gDGrJ9PK2L1zDwUJQHt9ldp6CTcT qPQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=s+BO5FOh; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a12si5613934edm.147.2021.01.18.04.48.53; Mon, 18 Jan 2021 04:49: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; dkim=pass header.i=@linaro.org header.s=google header.b=s+BO5FOh; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404051AbhARMqp (ORCPT + 99 others); Mon, 18 Jan 2021 07:46:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404225AbhARMlc (ORCPT ); Mon, 18 Jan 2021 07:41:32 -0500 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB10EC061574 for ; Mon, 18 Jan 2021 04:40:49 -0800 (PST) Received: by mail-wr1-x433.google.com with SMTP id a9so12864027wrt.5 for ; Mon, 18 Jan 2021 04:40:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=pUBLkn8FySf4zUY7MqtXXjbLm3L09Eo0TSDMqMBMKfM=; b=s+BO5FOhDlp/nvtnTNCkYC6pw9spNOEnIrmM8K3dL6rIqWMqrHTs4ctKLMPxUWh9bn V/XtJhkA7/T7NtgDrwnotnjn6IDm7cM3jHVSatn8EtA2s2bXb+SloN4taNrAVY/gCHKq 53Imgctex7mIxH2wd4piVk7A9h1ryVXK/B385VKK7GeUPFCaPscNRS0aKmudUQpjzjKu QuPWa9k+leDRdYbTtL53a/O74tP8BaOZuCz8s1LKKjCIinLJ9CDexduuXltbfdf8a+Tc O3Vys75aAG+nHFnw52+45/6WJqkIiXlTLiyczkt7RSz4QAZ4xuRs5gf0fvtwKJ6pbuMG e/cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=pUBLkn8FySf4zUY7MqtXXjbLm3L09Eo0TSDMqMBMKfM=; b=fwV2ALpWjnbsJ6ijUAJdDvmXCqawOkMrrcOedM0+jwhFgzM1KvF/BufMXZOFWqQ3Wi vhEP15+TvJkXbg8TBJIsoKFrTaxpPu8cUILHul7VqqMv39BGSmAUh5kJbc/xKdrW5g0i uIcIkvJvKk0RIiBlCU/orMKa6StA0CsorqT0lQMS8mpM1U5UCeIEJZI8YtpiWTq0XMaM Emq0tcAlDPMm10jV+3KK+Pv9xXWijR1qm5r0x3Ok5re1m4r1g5rMtHjFrcqdWhFcTeE9 PILgNU4xUZs2yecqIROiK5yQxbwPT8pSaAIG5TLEsLK+9nN42uDb8bpo7/AMr/Wp/FEP 3M2A== X-Gm-Message-State: AOAM531MgIupTsgXKpbeCNtwI4qYkwE+2F30vFa82+BiONvIYn0H8b/V hGKs9NPsJXW/CkLU6cfSPe4GHQ== X-Received: by 2002:adf:f7d2:: with SMTP id a18mr25320885wrq.47.1610973648680; Mon, 18 Jan 2021 04:40:48 -0800 (PST) Received: from myrica ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id u5sm9394625wmg.9.2021.01.18.04.40.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 04:40:48 -0800 (PST) Date: Mon, 18 Jan 2021 13:40:29 +0100 From: Jean-Philippe Brucker To: John Garry Cc: joro@8bytes.org, will@kernel.org, linux-kernel@vger.kernel.org, linuxarm@huawei.com, iommu@lists.linux-foundation.org, robin.murphy@arm.com Subject: Re: [PATCH v4 2/3] iommu/iova: Avoid double-negatives in magazine helpers Message-ID: 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 18, 2021 at 10:55:52AM +0000, 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. > > 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. I would have initially gone with option 2 which seems the simplest, but I don't have a setup to measure that overhead Thanks, Jean