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; From patchwork Thu Aug 9 11:48:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Leizhen \(ThunderTown\)" X-Patchwork-Id: 143824 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1994143ljj; Thu, 9 Aug 2018 04:50:44 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwhsTtEN8m4WbAgG0aWLU3uNpe5nZaoneibscPcFFxRUq1VDgGZfpGKAwiMDyixjNa+XYT+ X-Received: by 2002:a62:ccd0:: with SMTP id j77-v6mr2064165pfk.22.1533815444088; Thu, 09 Aug 2018 04:50:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533815444; cv=none; d=google.com; s=arc-20160816; b=m/rxpqgiugJP4fvMalrYkUMUMHzBCrsa0w/HYPaqRNRm9OZBemaljK6SnUc1surSLr 6SeZpSh/++rViumtY1TuqHioIppGzv5zJaVdxfwYZ7rx+mmERekwRyqWJVTchMpKAVWk lgN5FbLRVJwpI+4JDWi9Dwx1wQOKlvxmSNMlcmaA/muy1mle/3/iiNJl48mreeujRbD3 u1g1aGCVcbBSQ0gF4YEegFAZ2i65F+pVvrMUXSqkP+rUWLSgzyCezDuQJawoQ8ZwvI7K R8HFQC2GMdizXXs8DDJyBese1OIvXGOH7NJJ0AZxERaTS9Os0eEV7QjEnSUA6iXs3dDl iIpA== 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=J4rDfBWEG+Df37JIhovPchgG1lvgX5xsdOwHYZL/UqU=; b=ajqmO+XaEpKeeWQvLfrIcElXcrql57smSNhxJSP/3PyMW4ipISHRYlOncM+w3B0ct5 rjkAWWKE1HeNKmGZgRuAIKs/EgUPICCZzmkckThIVL0IITnacitttBMySmXu/r2px6v9 yuX06T8YL5fcr6Xll1c3Mp2QqudoOKLDfS7099RaO+KACkZ6eYJaKUgSWG5+BX+ub8xc BO/mvP8ooSwOdPYkRDSwkxXm+COXcHC9F/Y9o/s3IYVS4ufl0Kf1un51ImvkYZ+ztQ84 QOJHFxJoVHjmDMCv1UmIDTFgEFLJ54CM6jyHWJaier6HzMantU8p/YCn+QU+kiFcqhWa QZKQ== 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 b16-v6si5496679pgw.478.2018.08.09.04.50.43; Thu, 09 Aug 2018 04:50:44 -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 S1731135AbeHIOPM (ORCPT + 31 others); Thu, 9 Aug 2018 10:15:12 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:10649 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730090AbeHIOPM (ORCPT ); Thu, 9 Aug 2018 10:15:12 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id EA74812D1310B; Thu, 9 Aug 2018 19:50:36 +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; Thu, 9 Aug 2018 19:50:28 +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 2/2] iommu/arm-smmu-v3: avoid redundant CMD_SYNCs if possible Date: Thu, 9 Aug 2018 19:48:53 +0800 Message-ID: <1533815333-17320-3-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 More than two CMD_SYNCs maybe adjacent in the command queue, and the first one has done what others want to do. Drop the redundant CMD_SYNCs can improve IO performance especially under the pressure scene. I did the statistics in my test environment, the number of CMD_SYNCs can be reduced about 1/3. See below: CMD_SYNCs reduced: 19542181 CMD_SYNCs total: 58098548 (include reduced) CMDs total: 116197099 (TLBI:SYNC about 1:1) Signed-off-by: Zhen Lei --- drivers/iommu/arm-smmu-v3.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) -- 1.8.3 diff --git a/drivers/iommu/arm-smmu-v3.c b/drivers/iommu/arm-smmu-v3.c index d17a9a7..b96d2d2 100644 --- a/drivers/iommu/arm-smmu-v3.c +++ b/drivers/iommu/arm-smmu-v3.c @@ -567,6 +567,7 @@ struct arm_smmu_device { int gerr_irq; int combined_irq; u32 sync_nr; + u8 prev_cmd_opcode; unsigned long ias; /* IPA */ unsigned long oas; /* PA */ @@ -775,6 +776,11 @@ static int queue_remove_raw(struct arm_smmu_queue *q, u64 *ent) return 0; } +static inline u8 arm_smmu_cmd_opcode_get(u64 *cmd) +{ + return cmd[0] & CMDQ_0_OP; +} + /* High-level queue accessors */ static int arm_smmu_cmdq_build_cmd(u64 *cmd, struct arm_smmu_cmdq_ent *ent) { @@ -900,6 +906,8 @@ static void arm_smmu_cmdq_insert_cmd(struct arm_smmu_device *smmu, u64 *cmd) struct arm_smmu_queue *q = &smmu->cmdq.q; bool wfe = !!(smmu->features & ARM_SMMU_FEAT_SEV); + smmu->prev_cmd_opcode = arm_smmu_cmd_opcode_get(cmd); + while (queue_insert_raw(q, cmd) == -ENOSPC) { if (queue_poll_cons(q, false, wfe)) dev_err_ratelimited(smmu->dev, "CMDQ timeout\n"); @@ -952,9 +960,17 @@ static int __arm_smmu_cmdq_issue_sync_msi(struct arm_smmu_device *smmu) }; 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); + if (smmu->prev_cmd_opcode == CMDQ_OP_CMD_SYNC) { + /* + * Previous command is CMD_SYNC also, there is no need to add + * one more. Just poll it. + */ + ent.sync.msidata = smmu->sync_nr; + } else { + 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); return __arm_smmu_sync_poll_msi(smmu, ent.sync.msidata);