Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp4468470ybf; Wed, 4 Mar 2020 04:38:52 -0800 (PST) X-Google-Smtp-Source: ADFU+vtuvF5oDHtCpkJa0gQ/YXvpnFt2eU5k4dLbWjdTwtN95bEHYpU9HnUS4Wkrc3S0/rBw3R7L X-Received: by 2002:aca:cd43:: with SMTP id d64mr566149oig.40.1583325532793; Wed, 04 Mar 2020 04:38:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583325532; cv=none; d=google.com; s=arc-20160816; b=uvez8tYnfeixSOPhiq57QueJsK/KKojLPNuPoqr56zwK8j5pSBc/4F95ffrnmxaa70 0Xgj+WNsAbq1jzcFnx+t9ZfEZisQl14rq3kKSAszEmIGD2I7XwNBCvCf8akZW1K5qvVd FMlEvQ8vqanE0UwCYqsz11B+1QMkDNyJcfiDcG3UuTUQM8zDmD928S0PAySA+QMqHlTF n2TEcrq7BhHXW1ESUT4iJnokl4hd2JvJVVpgeCzJTolosLmf3HRPd4AZMEYmg5Nx42yB xNMIEIrMVVcKYrzD1F00z4YadsyymzmfjHBZEbdjlhe0lN5L+gPUzsdJcVWUtVvR2FxU 1Wnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=PUyzex+GAuRSylYQ7a7fj4ppMZsYY0nHrleZ2Kr3xlo=; b=LAjcRWiaJvx4KAcn8QUFbb+xxxehcqX65UtV85G1NW4WVbRPMHfTp3WfL4k7XJQ71/ TdozIZWmva7ELy+GZRCuZbtZVZ0RrWTKXBSWpLQkY9U8NI04n2xyRUqilj5HbDxO4eRD 9+3vAcKLA7VB6bYw6LE859ABdtDEFqRNwwixEfxCnCYnCbBgp66dAwP8RwznwbRmZiOz XR9enE/oOZ7W5ty/au4+vuKgrxtGDB0YwCbqNPgkIZYRJbTLzrfdhfeb0NwPWg3ORN+Q 7RFet6vMopOmM0Whf1xBvAPwTdMQ8gFaiZzsZmwljiatu8BVPshzSdf2ULWax9Dqz26X RIgg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d26si976462otc.6.2020.03.04.04.38.38; Wed, 04 Mar 2020 04:38:52 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388024AbgCDMg7 (ORCPT + 99 others); Wed, 4 Mar 2020 07:36:59 -0500 Received: from foss.arm.com ([217.140.110.172]:33774 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388005AbgCDMg6 (ORCPT ); Wed, 4 Mar 2020 07:36:58 -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 E353731B; Wed, 4 Mar 2020 04:36:57 -0800 (PST) Received: from [10.1.196.37] (e121345-lin.cambridge.arm.com [10.1.196.37]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F0CDB3F6C4; Wed, 4 Mar 2020 04:36:56 -0800 (PST) Subject: Re: [PATCH v2] iommu/dma: Fix MSI reservation allocation To: Marc Zyngier , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Eric Auger , Joerg Roedel , Will Deacon , stable@vger.kernel.org References: <20200304111117.3540-1-maz@kernel.org> From: Robin Murphy Message-ID: <35a91284-619e-398a-decc-2e3879702335@arm.com> Date: Wed, 4 Mar 2020 12:36:54 +0000 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20200304111117.3540-1-maz@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/03/2020 11:11 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 granule 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). > Fortunately, this only affects systems where the ITS isn't translated > by the SMMU, which are both rare and non-standard. > > Fix it by allocating iommu_dma_msi_page structures one at a time. Reviewed-by: Robin Murphy > Fixes: 7c1b058c8b5a3 ("iommu/dma: Handle IOMMU API reserved regions") > Signed-off-by: Marc Zyngier > Reviewed-by: Eric Auger > Cc: Robin Murphy > Cc: Joerg Roedel > Cc: Will Deacon > Cc: stable@vger.kernel.org > --- > * From v1: > - Got rid of the superfluous error handling (Robin) > - Clarified that it only affects a very small set of systems > - Added Eric's RB (which I assume still stands) > > drivers/iommu/dma-iommu.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c > index a2e96a5fd9a7..ba128d1cdaee 100644 > --- a/drivers/iommu/dma-iommu.c > +++ b/drivers/iommu/dma-iommu.c > @@ -177,15 +177,15 @@ static int cookie_init_hw_msi_region(struct iommu_dma_cookie *cookie, > start -= iova_offset(iovad, start); > num_pages = iova_align(iovad, end - start) >> iova_shift(iovad); > > - msi_page = kcalloc(num_pages, sizeof(*msi_page), GFP_KERNEL); > - if (!msi_page) > - return -ENOMEM; > - > for (i = 0; i < num_pages; i++) { > - msi_page[i].phys = start; > - msi_page[i].iova = start; > - INIT_LIST_HEAD(&msi_page[i].list); > - list_add(&msi_page[i].list, &cookie->msi_page_list); > + msi_page = kmalloc(sizeof(*msi_page), GFP_KERNEL); > + if (!msi_page) > + return -ENOMEM; > + > + msi_page->phys = start; > + msi_page->iova = start; > + INIT_LIST_HEAD(&msi_page->list); > + list_add(&msi_page->list, &cookie->msi_page_list); > start += iovad->granule; > } > >