Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp51012pja; Fri, 22 Nov 2019 03:19:22 -0800 (PST) X-Google-Smtp-Source: APXvYqzk+vTgt6hw/g0AO/0C6G9X1GPb1kGewRmJIv0w9LV4f86uEiSKMy4kMX8Stgg0++ZjUPey X-Received: by 2002:a17:906:c789:: with SMTP id cw9mr22070863ejb.40.1574421562303; Fri, 22 Nov 2019 03:19:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574421562; cv=none; d=google.com; s=arc-20160816; b=Cn3BF/GaVMCYC9SmzVWNwiLpPXb8ei/G+L4eXKWIATP7AUW04RLbHDaN1hqq9CdlHd EYAw6Dp/OAnQWF6yUz7pcWgatG57uDP70aAulw3+11dSIlaQo77X/3UOGk7kov2JO1VM D8R3fXjA74hYtbppeHIMcQajNFubjLo5evglRmUdBjJ8wU1upKIF5pRH+Qcidyg+0QNk L5YuXTsyndQ5+30TFQx8q88H0sDoJ6dXGRtRXYtGmG4qIomXEK3vwtuyEN9u/30+exHq Xq/JiAZkyDTpyk7pmwkGIuwgkusT9AZ49gJ1cfP7DzA2S5JB1RPVZtM41mdqBFV1VZpi NLCA== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/Jbsy/Md28+Pxg3BuH0Mz7TZb0bTnX7VaiCJVwLbJ0g=; b=ye6eXNGr8fyStV3RZ5KZ9wzheg7aK09TWduTWmkiOR/QTyn6tqgcM73ipqpDvWhtHL 1U6wSpdb0FqlZyZho4HpWOatMq22tWWLCD8cah9JYybF3MbDv70lzJtI7BP+zlNaY+F/ OidvTrU1oqW0JJ0GjkQyJGTw8MVp6LGGx39yZpuUBJWUYiob8fCXter+7C/Lo6N17Dzm qh7WhMngXUBPaJ9D/m786te8sGNEp9M7R9RxGCYNOe5+brr3YUqcTD52iac51Xlzz0nA sg1FaX3QmwHnay+3UDQOaK5Lre4A3tZi5Ad8bEtSEZOVnjuizleI0+C2iEJqBBrT6dEe D4Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cERXZQQh; 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 14si2058867edz.130.2019.11.22.03.18.57; Fri, 22 Nov 2019 03:19:22 -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=cERXZQQh; 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 S1729642AbfKVLQi (ORCPT + 99 others); Fri, 22 Nov 2019 06:16:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:60172 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729417AbfKVKuQ (ORCPT ); Fri, 22 Nov 2019 05:50:16 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 BDDA0205C9; Fri, 22 Nov 2019 10:50:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574419815; bh=gZnYs58YiVe5TChW7bml8wRKh6KmwgwD+XgFFTEa1qk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cERXZQQhBRWRcpJzPHw2ZTOGvYxQsWGR9MuAWDZCAaUYkWqID0OgfS2r2r4dHeM1E K8NpLubHUNudyFc1BpGOAobQTWm5DiK3pDKKKL5iafEdRXXfSGqfN/s3fjNuzcsr5n xZVBdLYcxeo8IjV3LzhWGtR4OrkhAw6IiEkDlorM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robin Murphy , Will Deacon , Sasha Levin Subject: [PATCH 4.14 019/122] iommu/io-pgtable-arm: Fix race handling in split_blk_unmap() Date: Fri, 22 Nov 2019 11:27:52 +0100 Message-Id: <20191122100735.999354490@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191122100722.177052205@linuxfoundation.org> References: <20191122100722.177052205@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robin Murphy [ Upstream commit 85c7a0f1ef624ef58173ef52ea77780257bdfe04 ] In removing the pagetable-wide lock, we gained the possibility of the vanishingly unlikely case where we have a race between two concurrent unmappers splitting the same block entry. The logic to handle this is fairly straightforward - whoever loses the race frees their partial next-level table and instead dereferences the winner's newly-installed entry in order to fall back to a regular unmap, which intentionally echoes the pre-existing case of recursively splitting a 1GB block down to 4KB pages by installing a full table of 2MB blocks first. Unfortunately, the chump who implemented that logic failed to update the condition check for that fallback, meaning that if said race occurs at the last level (where the loser's unmap_idx is valid) then the unmap won't actually happen. Fix that to properly account for both the race and recursive cases. Fixes: 2c3d273eabe8 ("iommu/io-pgtable-arm: Support lockless operation") Signed-off-by: Robin Murphy [will: re-jig control flow to avoid duplicate cmpxchg test] Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- drivers/iommu/io-pgtable-arm.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c index e8018a308868e..17a9225283dd1 100644 --- a/drivers/iommu/io-pgtable-arm.c +++ b/drivers/iommu/io-pgtable-arm.c @@ -551,13 +551,12 @@ static int arm_lpae_split_blk_unmap(struct arm_lpae_io_pgtable *data, return 0; tablep = iopte_deref(pte, data); + } else if (unmap_idx >= 0) { + io_pgtable_tlb_add_flush(&data->iop, iova, size, size, true); + return size; } - if (unmap_idx < 0) - return __arm_lpae_unmap(data, iova, size, lvl, tablep); - - io_pgtable_tlb_add_flush(&data->iop, iova, size, size, true); - return size; + return __arm_lpae_unmap(data, iova, size, lvl, tablep); } static int __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, -- 2.20.1