Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3650099ybf; Tue, 3 Mar 2020 09:47:20 -0800 (PST) X-Google-Smtp-Source: ADFU+vvwTqG0Y6ZqncBxm+6TM930z7QhkOt+dOndNIFVdn4NvUb56dEWd2eSXtN0DDtwHs0En5Gn X-Received: by 2002:a05:6830:129a:: with SMTP id z26mr142744otp.179.1583257640321; Tue, 03 Mar 2020 09:47:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583257640; cv=none; d=google.com; s=arc-20160816; b=FAjfB7VhKB/YAf0iGpb2FBm8zc2B0qQz0mqOJhJCmRJMzo4/2uYUCEc+t2nOnSI4ya qKfeDJSaVZ9c0a1QDaO1AS6uwnHRa9NvxzENhaPUEeSxgsfVdD1ecL/W99XlzI6PxOoi uQ/ubrKZ/7nv2kIlj1OnlTSKx+Mb3hm1v0kW6xD68RU5QtuI191Tq8/y6skLKe0jf8bB 3n4Smsr0EQlHx+wN7ILdm+l00v2456P6fKCUUX8QRWut26eAgLr1PDfBPiDDBQHvSpUs sguUFnaePDYDI+sD/QIKFbjam9Abj3iO4Vew0DLgBea45moRgadByjq4rk+hiz29IKee pi1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature; bh=pQFto1FSw8KR39PXS8zxQtloPFRFU3apRY8xSP0J7wk=; b=ptmpsyg3Sil64hxpVEav92/J8JrJRjLk5yJIAZa7yFkE8REhr4yE+ADfJz0PLf/9si XeCYyvqknrcAfd4PaowVgbnzoVyQniOq+oVcNEJ3Y68mxmjCqSmfzigg0bHrRHInUkPe ngsRPO4AHTXPdH2wnCam/ms5IjA1e/RRiQthzH1Wd+xLT7tsreDFZpRkqvbRN9A1ihgD U6rXuOJy9avTuN9vyVOXwatoYfnTEJqqjQ86qtiwNHk2cMotZgnu8N8pYTJwDjACUd6i GXK1+UMhLR4Zf+kWTs0eOGH+CZDos6UD4UlFVJ70OTVNVpZpv/21kgVu0r3HUS1j9mUq aIAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PssTJb+5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s70si7245927oie.178.2020.03.03.09.47.07; Tue, 03 Mar 2020 09:47:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PssTJb+5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730464AbgCCReB (ORCPT + 99 others); Tue, 3 Mar 2020 12:34:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:47176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730440AbgCCReB (ORCPT ); Tue, 3 Mar 2020 12:34:01 -0500 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BA97A2146E; Tue, 3 Mar 2020 17:33:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583256839; bh=iPOYluEY+ZO1uyD5kIymeUNRinPpcpWzEsgkKtWHXKk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=PssTJb+5WAlQiBvvTwCxPLcnNVAQWPTDSLFFFkPWblU0Tw3d2NnBnuKJhMGo2iJ4/ udmQSQKATNt7HuovAY5BY+JsaxblFdHhEW6mvR8mZgogCM+29GHHS7gJeFvKnHGXD+ WvRlzPNtr7KjGCMKufGhmxLDK4SNmIVSspxzoR48= Received: from disco-boy.misterjones.org ([51.254.78.96] helo=www.loen.fr) by disco-boy.misterjones.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j9BQc-009jyt-0c; Tue, 03 Mar 2020 17:33:58 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 03 Mar 2020 17:33:57 +0000 From: Marc Zyngier To: Robin Murphy Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joerg Roedel , Eric Auger , Will Deacon , stable@vger.kernel.org Subject: Re: [PATCH] iommu/dma: Fix MSI reservation allocation In-Reply-To: References: <20200303115154.32263-1-maz@kernel.org> Message-ID: X-Sender: maz@kernel.org User-Agent: Roundcube Webmail/1.3.10 X-SA-Exim-Connect-IP: 51.254.78.96 X-SA-Exim-Rcpt-To: robin.murphy@arm.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, jroedel@suse.de, eric.auger@redhat.com, will@kernel.org, stable@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-03-03 17:23, Robin Murphy wrote: > On 03/03/2020 11:51 am, Marc Zyngier wrote: >> The way cookie_init_hw_msi_region() allocates the iommu_dma_msi_page >> structures doesn't match the way iommu_put_dma_cookie() frees them. >> >> The former performs a single allocation of all the required >> structures, >> while the latter tries to free them one at a time. It doesn't quite >> work for the main use case (the GICv3 ITS where the range is 64kB) >> when the base ganule size is 4kB. >> >> This leads to a nice slab corruption on teardown, which is easily >> observable by simply creating a VF on a SRIOV-capable device, and >> tearing it down immediately (no need to even make use of it). >> >> Fix it by allocating iommu_dma_msi_page structures one at a time. > > Bleh, you know you're supposed to be using 64K pages on those things, > right? :P lalalala... ;-) [...] >> + if (!msi_page) { >> + ret = -ENOMEM; > > I think we can just return here and skip the cleanup below - by the > time we get here the cookie itself has already been allocated and > initialised, so even if iommu_dma_init_domain() fails someone else has > already accepted the responsibility of calling iommu_put_dma_cookie() > at some point later, which will clean up properly. Ah, that's a very good point. I'll refresh the patch with a simplified error handling. Thanks, M. -- Jazz is not dead. It just smells funny...