Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1343329rwr; Wed, 26 Apr 2023 13:35:53 -0700 (PDT) X-Google-Smtp-Source: AKy350bHnKzyfTRdi3bzP/tTHdwfv06Ii8afzz1AtdroAq42nRoW095uf6PkwhXolQNiMejXDBj3 X-Received: by 2002:a17:903:24e:b0:1a6:4a64:4d27 with SMTP id j14-20020a170903024e00b001a64a644d27mr27261882plh.40.1682541352706; Wed, 26 Apr 2023 13:35:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682541352; cv=none; d=google.com; s=arc-20160816; b=cRJ90gP/dkdp+rjW62UyWDl2eXTlpYKxcFrwcz7YnZfWxE3/cdI3WhRMx9MenfDC9u 6ZSnEoWqMB60dGBv2/69EsI8qQoiCHJ7YuBzn0B1zeATEbKKI3oPWCF3yAZQIB06df5b pq66RNyQPOk/EQoqFPfcJo9FjfM85Y+mB9Oed/JCCNIPmEC5eaeRBDVuxXIfb2rtOPKp CWnjOyPXZ9P2suI8nrQL4gR6FZxj8IzQ7cheCBOE694IRXSDWf4CCV/IqCKXoj58Anqy Bpiq8ItrZQnTmz3PJmRzSYzOZ1NmxVE0nBS9ZoMoKu5axqGDgWT3sb9vNToKeit1aXK0 HYPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=MsgPsrUA7pZr2poVzmEsLw5CPMy5beCZQnaEI4bsMpM=; b=F9xUaA/4vhgU5JJY+6yva5FGPlFABvhHeT76Y/s+H8OAmJZ3m5Cyv0PvvLJ4HHKoJR qb0HWnKBlukBH4T4lIP+KXY6zi5Uc5UkBaW6TPT3uk3D/l7NQ+8wC/gmBD4r6FFNp8d3 2cs1FeH2F46RF3Gh+4zem/ugf8rKUrY++zinZIOzHtn2rOFJC8tIdtDpI9acYPGccz2r R2y5eUjKkPXm++fh/cFMC1FPCg/GQ9wVnr51Xi9zBGvsFSKNAiVmesjHKuAP/mKxxJ/O wxlOiR4WW8H9OALDT57RP+AM/E8tlNySJe3DiAhbIEbm+BMNGiLgukzJDXRNBPZLORrs +Beg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=7ktCRMMX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d12-20020a170902654c00b001a6db2bef24si15941418pln.145.2023.04.26.13.35.28; Wed, 26 Apr 2023 13:35:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=7ktCRMMX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236017AbjDZUdD (ORCPT + 99 others); Wed, 26 Apr 2023 16:33:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229889AbjDZUdB (ORCPT ); Wed, 26 Apr 2023 16:33:01 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54FBF212E for ; Wed, 26 Apr 2023 13:33:00 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-54f8a3f1961so68092617b3.0 for ; Wed, 26 Apr 2023 13:33:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682541179; x=1685133179; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=MsgPsrUA7pZr2poVzmEsLw5CPMy5beCZQnaEI4bsMpM=; b=7ktCRMMXoavpPo+oNTHeDKKUE2nqiLnaUL0Jez61kvhTdEzPAgY8c1dYCLPFVJtNRi o1DulXO9gD+Xp0GRoZUnkFK0T7HZ/WfLMpHP3P54mLE7Zmh7a7IjFshrDUqbWrHPC4UY cYKUojkhCq07wF45ihjARmMr2sp+yrq/CgxnZsU9rBoHVGmbia8wHhq+W7NxaIbTxd7T ARNxmVD2aVEJm4OQJG3ycIGd/vDp965VXtQPCWTR/5urg1B6JByEbdsUctVLFB906sri RZofaQPIYN0eZo9ETpL5eBauFErEy5zTs/eji8Edo2r/ykhhSUtXqr8tKcAAa5p6yEcK Cl5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682541179; x=1685133179; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=MsgPsrUA7pZr2poVzmEsLw5CPMy5beCZQnaEI4bsMpM=; b=OMA/6GTYArsI0IE3SI3KR2cyAxHvrUUKVabp+XEpC59Q0LpdSyIGqeoLqxxfz+DYUw YiB6r6lEqr5+VnBPu0sLni9SkCLAXFrgjDicvk8ckBuFloZfh4z0PMmho5oToDc2X4fa AIHGWx+QJ3s7Aq1P2drl+UsftwUFBrjmERNLTV+kou7R+7yCGvhFqJu0bY9Cw04VnljZ eecwJ9iCWiOusidHKP8J+956qMnVCGgWXPuMsLJVTGMlKwQ2MvulUp+qTftgwNJeN1DW Cdmx0G5ej9I3LKkUJKzyQ137NCSbRhpMbcgXLJJasJtWWmZY+vCC8wIJF7V+zUad11Jt 8Xyg== X-Gm-Message-State: AAQBX9d7JRGXvIveKR/7EGlInRrUEp2NHlWvMTZb6IpmikgsnWlcTL3W 0XyRINq/WazSYX4f6+2A8iUSJ4IXqBI= X-Received: from pandoh.svl.corp.google.com ([2620:15c:2c5:11:cf46:dfd0:d5c4:864c]) (user=pandoh job=sendgmr) by 2002:a81:450c:0:b0:545:883a:544d with SMTP id s12-20020a81450c000000b00545883a544dmr10795000ywa.9.1682541179541; Wed, 26 Apr 2023 13:32:59 -0700 (PDT) Date: Wed, 26 Apr 2023 13:32:56 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Message-ID: <20230426203256.237116-1-pandoh@google.com> Subject: [PATCH] iommu/amd: Fix domain flush size when syncing iotlb From: Jon Pan-Doh To: Joerg Roedel , Suravee Suthikulpanit Cc: Will Deacon , Robin Murphy , Nadav Amit , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Jon Pan-Doh , Sudheer Dantuluri , Gary Zibrat Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When running on an AMD vIOMMU, we observed multiple invalidations (of decreasing power of 2 aligned sizes) when unmapping a single page. Domain flush takes gather bounds (end-start) as size param. However, gather->end is defined as the last inclusive address (start + size - 1). This leads to an off by 1 error. With this patch, verified that 1 invalidation occurs when unmapping a single page. Fixes: a270be1b3fdf ("iommu/amd: Use only natural aligned flushes in a VM") Signed-off-by: Jon Pan-Doh Tested-by: Sudheer Dantuluri Suggested-by: Gary Zibrat --- drivers/iommu/amd/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 5a505ba5467e..da45b1ab042d 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -2378,7 +2378,7 @@ static void amd_iommu_iotlb_sync(struct iommu_domain *domain, unsigned long flags; spin_lock_irqsave(&dom->lock, flags); - domain_flush_pages(dom, gather->start, gather->end - gather->start, 1); + domain_flush_pages(dom, gather->start, gather->end - gather->start + 1, 1); amd_iommu_domain_flush_complete(dom); spin_unlock_irqrestore(&dom->lock, flags); } -- 2.40.0.634.g4ca3ef3211-goog