From patchwork Mon Aug 6 12:31:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 143509 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3233297ljj; Mon, 6 Aug 2018 05:32:06 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd3vl/etYshyKSUJUVypcXiclhM5hg7RF16rNF4xDVPpA8LEqHOEstDw1ndq1KfUN9Nsp4+ X-Received: by 2002:a63:ef10:: with SMTP id u16-v6mr14631777pgh.269.1533558726011; Mon, 06 Aug 2018 05:32:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533558726; cv=none; d=google.com; s=arc-20160816; b=GujxzrV4t/8oFtzWHQp0cV3UwS0Cj5YOOD99t9rbTurt8MwhCllbun6B3n4Vi3MFTD I0Mx1r57KoXEjy8XBVcrQZnBMfLih4jMArajoGhazdVAVslfoSx1ht+32QOjkBAxX4p9 4TRMkK1qqToJZigjx4mpBD2gHoRkwTEdVLcz//McgO7hcpLKnOG1ddNRLf3ny+q5FT0o 9Io/YnBCDAuuY0PoJ0fLRBAlfuTpZoytZbkNdD/CHLk6PfoM4PSzOqHSYxkpYrgJl1wC JPPG95GlqYEkejRN7efY7w954a84v/x26GxJ4Jz1vQpIoUSly5i4IPZYaPGAt/IrQC3j tkXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=ttmP3m35x6Ta1V04sXc72WtCSclZyun39NS86pYvH6A=; b=cKWHRnDQJQQvTufl8214nvMW4yvR0oA9WEPXYyQnGgR9oXOzzt7U6vWvivgIrDIZ6+ P7nOK04cD8U/o0K0ii0EuEDE5t+MCckesYszcWNNt+R8JsenN31dRWbFwZCZfFQA/us1 MBwcvXr3Ex8MxHMw1sPt28c3w+BvU4zdTfOcMOOWdlP+lXIo7dJ7j/33uiY5B91FRx1i 2cOObZYAqObQiaCLG8ApAvCAyGTlWk17ky+PzzLb1GIqdsxnDF/MpDW355HltWiFVsV1 UPbGkCphPRReHLcQE9ojc4+ZeCHwrC8EW4lfx+7G8+L6PNN0pCM26v2qhTW/vCzeh27O nqsQ== 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 s71-v6si14166819pfa.367.2018.08.06.05.32.05; Mon, 06 Aug 2018 05:32:05 -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 S1731081AbeHFOk5 (ORCPT + 31 others); Mon, 6 Aug 2018 10:40:57 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:41524 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727451AbeHFOk5 (ORCPT ); Mon, 6 Aug 2018 10:40:57 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 60C0F5ADB2FA1; Mon, 6 Aug 2018 20:32:00 +0800 (CST) Received: from localhost (10.177.23.164) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.399.0; Mon, 6 Aug 2018 20:31:52 +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 1/1] iommu/arm-smmu-v3: fix unexpected CMD_SYNC timeout Date: Mon, 6 Aug 2018 20:31:29 +0800 Message-ID: <1533558689-3000-1-git-send-email-thunder.leizhen@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.0 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. Signed-off-by: Zhen Lei --- drivers/iommu/arm-smmu-v3.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) -- 1.8.3 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index 1d64710..4810f61 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 */ @@ -836,7 +836,6 @@ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent) cmd[0] |= FIELD_PREP(CMDQ_SYNC_0_CS, CMDQ_SYNC_0_CS_SEV); cmd[0] |= FIELD_PREP(CMDQ_SYNC_0_MSH, ARM_SMMU_SH_ISH); cmd[0] |= FIELD_PREP(CMDQ_SYNC_0_MSIATTR, ARM_SMMU_MEMATTR_OIWB); - cmd[0] |= FIELD_PREP(CMDQ_SYNC_0_MSIDATA, ent->sync.msidata); cmd[1] |= ent->sync.msiaddr & CMDQ_SYNC_1_MSIADDR_MASK; break; default: @@ -947,7 +946,6 @@ 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), }, }; @@ -955,6 +953,8 @@ static int __arm_smmu_cmdq_issue_sync_msi(struct arm_smmu_device *smmu) arm_smmu_cmdq_build_cmd(cmd, &ent); spin_lock_irqsave(&smmu->cmdq.lock, flags); + ent.sync.msidata = ++smmu->sync_nr; + cmd[0] |= FIELD_PREP(CMDQ_SYNC_0_MSIDATA, ent.sync.msidata); arm_smmu_cmdq_insert_cmd(smmu, cmd); spin_unlock_irqrestore(&smmu->cmdq.lock, flags); @@ -2179,7 +2179,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;