From patchwork Thu Aug 9 11:48:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 143823 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1994107ljj; Thu, 9 Aug 2018 04:50:42 -0700 (PDT) X-Google-Smtp-Source: AA+uWPziFH2Bo1QLfV2TugfKCsyIpqc4hm7sT0yfdQACqBW9RrABNxd2M4MZWnSOYw+0CsNnC5Hd X-Received: by 2002:a62:9f1d:: with SMTP id g29-v6mr1980230pfe.207.1533815442114; Thu, 09 Aug 2018 04:50:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533815442; cv=none; d=google.com; s=arc-20160816; b=IeGAzL+pJSBT4Ccmjcpt0G6cBDEECvMeoQvgJyJJIMximN8f2bvVDFd7BOJl/Uuwo7 tXwch9O0/igEsTCiUL3K/QbM0YFE4IHkHNhNjO/ZADq7R0Bx19WxETj5mRY0YObIws+R Uzrkdg6q5NfKfpYj+DMdDNRC7IBCMx2a9ACwqiBOyh2j+EGDh9cwi4nCDokpxMfmoWOP g1pg7bjmwFb6KjUfLHaJyiy+36mFzQzOK062Wx+K/PciKiSCxBtdLzQpFAArgjkDOQ/w nAWiOJ+83jvuLrGAKnexQ2Z7OwbCtpP4hToPb6NKjYFXcqXi3c/16rNTvdWHyU0DfgtL Fu5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=TGm7Jx9h+PIMHier1puN5lIEiBJxnbMGzXfo5MNjD48=; b=zAOou5IwJP4LcIKqTgbmOVmhAsFR2Yht9lS4nlTrqG6ZgE10UE8k9AKyUQ8JvHpRtH 1yMo43cSkJRInNimQK7hfxpfBhjFHvZqAp01uqgriZ+we73LqsnzZpjbjB+MsgqhHJTY /10FhW4Sxlguqy81krGsvmjOUJi6bdhAUvIy3ugaun1n5R4jSxZ4/uto/CV+8kwspdqj kxwm72hbN7TPjUJ9rGoDMk4WpngBEAX65wD7mJXYdByM7EFiHhvNnfH754j+sU86UC+w mfbPOF+EQbes8IDbDZ4OyBPss0LVInLnKNdOnzgxrjFYvkMAgTtaQKQFgcSSxVQ8mv/o rp1A== 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 u6-v6si7590819pfu.143.2018.08.09.04.50.41; Thu, 09 Aug 2018 04:50:42 -0700 (PDT) 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 S1731109AbeHIOPK (ORCPT + 31 others); Thu, 9 Aug 2018 10:15:10 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:10688 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730090AbeHIOPI (ORCPT ); Thu, 9 Aug 2018 10:15:08 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id EAD3249A3C293; Thu, 9 Aug 2018 19:50:32 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.399.0; Thu, 9 Aug 2018 19:50:27 +0800 From: Zhen Lei To: Robin Murphy , Will Deacon , Joerg Roedel , linux-arm-kernel , iommu , linux-kernel CC: Zhen Lei , LinuxArm , Hanjun Guo , Libin Subject: [PATCH v2 1/2] iommu/arm-smmu-v3: fix unexpected CMD_SYNC timeout Date: Thu, 9 Aug 2018 19:48:52 +0800 Message-ID: <1533815333-17320-2-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1533815333-17320-1-git-send-email-thunder.leizhen@huawei.com> References: <1533815333-17320-1-git-send-email-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.23.164] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The condition "(int)(VAL - sync_idx) >= 0" to break loop in function __arm_smmu_sync_poll_msi requires that sync_idx must be increased monotonously according to the sequence of the CMDs in the cmdq. But ".msidata = atomic_inc_return_relaxed(&smmu->sync_nr)" is not protected by spinlock, so the following scenarios may appear: cpu0 cpu1 msidata=0 msidata=1 insert cmd1 insert cmd0 smmu execute cmd1 smmu execute cmd0 poll timeout, because msidata=1 is overridden by cmd0, that means VAL=0, sync_idx=1. This is not a functional problem, just make the caller wait for a long time until TIMEOUT. It's rare to happen, because any other CMD_SYNCs during the waiting period will break it. Signed-off-by: Zhen Lei --- drivers/iommu/arm-smmu-v3.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) -- 1.8.3 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 1d64710..d17a9a7 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -566,7 +566,7 @@ struct arm_smmu_device { int gerr_irq; int combined_irq; - atomic_t sync_nr; + u32 sync_nr; unsigned long ias; /* IPA */ unsigned long oas; /* PA */ @@ -947,14 +947,13 @@ static int __arm_smmu_cmdq_issue_sync_msi(struct arm_smmu_device *smmu) struct arm_smmu_cmdq_ent ent = { .opcode = CMDQ_OP_CMD_SYNC, .sync = { - .msidata = atomic_inc_return_relaxed(&smmu->sync_nr), .msiaddr = virt_to_phys(&smmu->sync_count), }, }; - arm_smmu_cmdq_build_cmd(cmd, &ent); - spin_lock_irqsave(&smmu->cmdq.lock, flags); + ent.sync.msidata = ++smmu->sync_nr; + arm_smmu_cmdq_build_cmd(cmd, &ent); arm_smmu_cmdq_insert_cmd(smmu, cmd); spin_unlock_irqrestore(&smmu->cmdq.lock, flags); @@ -2179,7 +2178,6 @@ static int arm_smmu_init_structures(struct arm_smmu_device *smmu) { int ret; - atomic_set(&smmu->sync_nr, 0); ret = arm_smmu_init_queues(smmu); if (ret) return ret;