From patchwork Sat Nov 18 15:50:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 13460154 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45EEAC5ACB3 for ; Sat, 18 Nov 2023 15:52:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PcYaZNxJXvQfQh34yL6cFtvO3bvqP9MAoSXtYCK9zrI=; b=jkk6wkMPIHDYt/ At9d1Y39ayBH+eFed8yrgqclBQk767laDmYPGlrVe23xQIzcTCx2bDfgv4wc7cYr69iyIpviozsc6 Gta59uxYJ5eLfQUhL33Vf3qpVriXfCqmOHc+FqWV5OOvnaUOEchFxwWMXRtKfmBjsGvzj3T3xPEoe Ep51vh7y4HtVe3LMywlumlrTNLefqMDnX5uk+xjeNn0XnXYo8rGoP07eMi9TwWHBGdvnFb6QkqreF /oZdwn0DFMELGlXHomTTJzLDu1TPLP04pB4jz/Mg+tKh1MZgf60cNe9sqHFMi3GOBgGwN+yCuZFiB DnFsgMmz9NnBsSJXFtEg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r4Nbf-008lIu-26; Sat, 18 Nov 2023 15:51:39 +0000 Received: from mail-yw1-x1132.google.com ([2607:f8b0:4864:20::1132]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r4Nbb-008lFv-2k for linux-arm-kernel@lists.infradead.org; Sat, 18 Nov 2023 15:51:38 +0000 Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-5c8ebf18a21so9327127b3.2 for ; Sat, 18 Nov 2023 07:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700322695; x=1700927495; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=V1XoIiNxFuF4VYuiH6Quz1F4aXv1fFJNE5bF8jDHsU4=; b=imYrh0QJwfi9O+jQ/f/zDqDXWQ8Kb5bwsueOA7C0d7uhss6+Mb4Inqvnsmgo8q9nAw xt82L1LxJ8MgqEg5YVFGMFBmjvFFtsmhjt/yqhBAt4BqWekqrGtPT3hZL6zOdmBmNhbO 4vF2+i4FVnmEMUp+zoFrGH6RO4VZZyw78QjOnzyfdjGU5Gz+IcnKDROvyxVY5AlhEpVt OPKgCSeWjFxEo9ZUf/ZgvXJTtza/jIRYPTHavD32sEp90p5svwt+kBLLK1liM5y+brUr p9MNaAcwfN/WxkL34SXaHdiE6Kpb5YajTHPHAmlFL7q3LfeUDi11C5ZtHBNFJpxdykGH fFBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700322695; x=1700927495; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=V1XoIiNxFuF4VYuiH6Quz1F4aXv1fFJNE5bF8jDHsU4=; b=nLPRSOo41xpZ1Z01ss/V4jH28cs+81MGVQzzKPbCYdeeowq8vuPiKFvB7MRSc8HoO6 nR2PfqUzQmQ70Yno+6WrBYtbrBeviVf7nk6YhZGY4+lMuXSTg9aQfj4W9OWawbKF4CPj 2TrVHgu3mWEXxCkv7h8TGmOqA/n75FS7swnQClLxbZ5usw4nQgJjYxhJnf0bk98KI6/a Oa5gcZHHlSsfWgIsKi5xjHs10cYcIZl+dZzeB25PF4ymsiPht4Xeg7IjEGBGaxuYdmBY IT9h/cRrrd7+AuXJUFILhOEqzWM/gm7UmMXesDC4r6qqxDsjqn1oTIWv3A3YSasTVTPr 10ZA== X-Gm-Message-State: AOJu0Ywqupbc+iXPfanwTBulCUh7asaaIyxJK2w27vyxn4c5HovUfvn8 5Mo3OA3VVTPanGakjlIMDd0= X-Google-Smtp-Source: AGHT+IEY1WAEs4kNKd75UVdANlei8VDfd1gVdWYThj+rx1F0zxh+1GBN8rubfJYMqdp79r+pN+9YDQ== X-Received: by 2002:a81:8447:0:b0:5a7:a81d:e410 with SMTP id u68-20020a818447000000b005a7a81de410mr3105570ywf.18.1700322695050; Sat, 18 Nov 2023 07:51:35 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:48a9:bd4c:868d:dc97]) by smtp.gmail.com with ESMTPSA id h12-20020a816c0c000000b005c5a3f80239sm1158114ywc.88.2023.11.18.07.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 07:51:34 -0800 (PST) From: Yury Norov To: linux-kernel@vger.kernel.org, Will Deacon , Robin Murphy , Joerg Roedel , Andy Gross , Bjorn Andersson , Konrad Dybcio , Yury Norov , linux-arm-kernel@lists.infradead.org, iommu@lists.linux.dev, linux-arm-msm@vger.kernel.org Cc: Jan Kara , Mirsad Todorovac , Matthew Wilcox , Rasmus Villemoes , Andy Shevchenko , Maxim Kuvyrkov , Alexey Klimov Subject: [PATCH 17/34] iommu: use atomic find_bit() API where appropriate Date: Sat, 18 Nov 2023 07:50:48 -0800 Message-Id: <20231118155105.25678-18-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231118155105.25678-1-yury.norov@gmail.com> References: <20231118155105.25678-1-yury.norov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231118_075135_888811_4F4685BF X-CRM114-Status: GOOD ( 14.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Fix opencoded find_and_set_next_bit() in __arm_smmu_alloc_bitmap() and msm_iommu_alloc_ctx(), and make them nice one-liner wrappers. While here, refactor msm_iommu_attach_dev() and msm_iommu_alloc_ctx() so that error codes don't mismatch. Signed-off-by: Yury Norov --- drivers/iommu/arm/arm-smmu/arm-smmu.h | 10 ++-------- drivers/iommu/msm_iommu.c | 18 ++++-------------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.h b/drivers/iommu/arm/arm-smmu/arm-smmu.h index 703fd5817ec1..004a4704ebf1 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h @@ -453,15 +453,9 @@ struct arm_smmu_impl { static inline int __arm_smmu_alloc_bitmap(unsigned long *map, int start, int end) { - int idx; + int idx = find_and_set_next_bit(map, end, start); - do { - idx = find_next_zero_bit(map, end, start); - if (idx == end) - return -ENOSPC; - } while (test_and_set_bit(idx, map)); - - return idx; + return idx < end ? idx : -ENOSPC; } static inline void __iomem *arm_smmu_page(struct arm_smmu_device *smmu, int n) diff --git a/drivers/iommu/msm_iommu.c b/drivers/iommu/msm_iommu.c index f86af9815d6f..67124f4228b1 100644 --- a/drivers/iommu/msm_iommu.c +++ b/drivers/iommu/msm_iommu.c @@ -185,17 +185,9 @@ static const struct iommu_flush_ops msm_iommu_flush_ops = { .tlb_add_page = __flush_iotlb_page, }; -static int msm_iommu_alloc_ctx(unsigned long *map, int start, int end) +static int msm_iommu_alloc_ctx(struct msm_iommu_dev *iommu) { - int idx; - - do { - idx = find_next_zero_bit(map, end, start); - if (idx == end) - return -ENOSPC; - } while (test_and_set_bit(idx, map)); - - return idx; + return find_and_set_bit(iommu->context_map, iommu->ncb); } static void msm_iommu_free_ctx(unsigned long *map, int idx) @@ -418,10 +410,8 @@ static int msm_iommu_attach_dev(struct iommu_domain *domain, struct device *dev) ret = -EEXIST; goto fail; } - master->num = - msm_iommu_alloc_ctx(iommu->context_map, - 0, iommu->ncb); - if (IS_ERR_VALUE(master->num)) { + master->num = msm_iommu_alloc_ctx(iommu); + if (master->num >= iommu->ncb) { ret = -ENODEV; goto fail; }