From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BnlSM+sE" Received: from mail-yw1-x1132.google.com (mail-yw1-x1132.google.com [IPv6:2607:f8b0:4864:20::1132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 939D01BD7; Sun, 3 Dec 2023 11:33:44 -0800 (PST) Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-5d05ff42db0so42210827b3.2; Sun, 03 Dec 2023 11:33:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701632022; x=1702236822; darn=vger.kernel.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=vguNRNHZWUrDOSu/TVKVOPIB86L1io3LlGEpKJkKhiw=; b=BnlSM+sEOduvbEUrrvCDcvg+vYlF5hKVKUkmiSk20y+NXZ9rlfSFBC/XxwGXu5FxnQ OlZgRkfBLkFgr05ufkOc0kNxcSpiDLoBYJxmjX3oSyl1DVw8mQ+OrQmgaiWTm34E5oSX a5vBPq/t9S2WHl3qKcrmyrK1l+TTV4/nll23ZlhcEAw0Mz6zRG5M6wqOAnHkWIPNGFuq baLJeW9UzP7qWRaTB2MYyBJ2ieydGukGKUviNHKT4/tf1za6SsgC1TyhNh4Z80T01saR h4Mi5/Pmmf7FYTLEHZ/rYDlmpZ2PBZOqLYv8EQyDOPMyfkSiHuEz+Fnurd1cu8dfpDJL lEHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701632022; x=1702236822; 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=vguNRNHZWUrDOSu/TVKVOPIB86L1io3LlGEpKJkKhiw=; b=gVhYNGIpHnlP0Swz4VKfhieUzc1u1Sn7WBUKlE0/GDvT8vHe1IuMmbJrZcYJvirVZJ ZNNd0u5c483ckzVfRkZ7QKSsSRHYgU/rcsO9+HbuFNTRI1SzWMQmYnZuiHfER/NRo4eB hyREQEwisSG6Elyi6KI0MFtDtmwRNTbEL4eZbPiXyLgoJbW240PBf8vxqDU1DIGSoh3n 5HpN2vICySn0mncf9o4YXZ5QrifCyuu1XFmHf5h8fXTbVoXdViA+D6x4PXhutaoOvlD7 M0oX6xtMoLtkTD0St/mQu2aFUzqpQPnpISuJXmFEKBI/O46FKXKhFBd6vnmk5LKNpDYO K6eA== X-Gm-Message-State: AOJu0Yw1guZMuv8NCiiuvpWm1KOmExUEo4o/ClUHhU5JVHnFxbTT7gGg 5ejSiDR7AcyghB9FGx9pAIQInWumTTk75Q== X-Google-Smtp-Source: AGHT+IFSv+65IiQiN8WCGcLVQvQiuR6hHdW5qXQ7nf6ECXpLpXmmUxxmzvhwBggjw2vBz5nonWlXlg== X-Received: by 2002:a05:690c:3745:b0:5d8:5fad:8dcc with SMTP id fw5-20020a05690c374500b005d85fad8dccmr507589ywb.29.1701632022542; Sun, 03 Dec 2023 11:33:42 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:cb98:c3e:57c:8191]) by smtp.gmail.com with ESMTPSA id m190-20020a0dfcc7000000b005463e45458bsm2765478ywf.123.2023.12.03.11.33.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 11:33:41 -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 , Bart Van Assche , Sergey Shtylyov Subject: [PATCH v2 19/35] iommu: use atomic find_bit() API where appropriate Date: Sun, 3 Dec 2023 11:32:51 -0800 Message-Id: <20231203193307.542794-18-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231203193307.542794-1-yury.norov@gmail.com> References: <20231203192422.539300-1-yury.norov@gmail.com> <20231203193307.542794-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Switch opencoded find_and_set_next_bit() in __arm_smmu_alloc_bitmap() and msm_iommu_alloc_ctx() to use dedicated API, 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; } -- 2.40.1 From mboxrd@z Thu Jan 1 00:00:00 1970 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 7E2DFC4167B for ; Sun, 3 Dec 2023 19:34:08 +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=Uh3PNWHrtFyDzz8M8/rn1Fdwny54eaBhHmGm2SuZLh8=; b=NvAlS4sbdY4QuU W32PSSM7XQW5HjYmdagfU8IlgGw9lSvMDgYLSNRtLYqMHL3UVcmAjuqiO0GFbKgvVXP9zJ36xDofT kxWcXjrI0U04ghi2C+gNqViuPDLnwnV47hilw5tI6FtBObqJvH/lW6CxHhSA07dYHp47aoiszDFeh nU17U2lI8V2w9cNef8HPpWVUbPE5/n53L6rqDrrrFSJmKk4WaCAo+2eJRv9cfL5eHKCFdKgO7Rtkk 0GG2EXaAis5U1N2sZykejXjkMvuKpWzRvJ4iRO4xD7Fl8RAk4l+LaA7zkWhrJGNQm282Pz1LSfpyL TSTfFf1TY+l2TlI5Lw1g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r9sDq-002WGO-04; Sun, 03 Dec 2023 19:33:46 +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 1r9sDn-002WED-1D for linux-arm-kernel@lists.infradead.org; Sun, 03 Dec 2023 19:33:44 +0000 Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-5c8c26cf056so42215847b3.1 for ; Sun, 03 Dec 2023 11:33:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701632022; x=1702236822; 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=vguNRNHZWUrDOSu/TVKVOPIB86L1io3LlGEpKJkKhiw=; b=JY71bYNTokQqAUWGoPm9PjtAl16phqwWThEgLw0DsX/FNW1jq8Nj2PCdznsFjpbgAR 9Zi/e4VPpQa+kGfZ4vpoXwmbAXnkB2zdtgdlf5gdy7DsBeCQIYkOIF3U2Yd/ageDPF3m VhMiCp2waBQCtkqFo56rrDOlB7vwZ17q/1yecrg2wQ49nkX7/WiHYaNB05mSRqw6ABBz v8fPs1D9RA1AtagOEY3VpcvGAeFoGQwBSSMzVxWuj0Tvb+7YGPiU+1LuTfnLUonyommE wrpsefcux7UhlRsFGxXeQf7/yaGYps/1APTfGS8R4YAuETXk8CJyCF/Zt5fgNyBX6X8K 3uJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701632022; x=1702236822; 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=vguNRNHZWUrDOSu/TVKVOPIB86L1io3LlGEpKJkKhiw=; b=twAPZp1i2Ro37Lj5NDhgwliwlusmp2HgJ4yTWxnKmN3i5wK4ooaW6W3u3aLtIdUv4z OR7dv+QM5WWa4f6A9qLo8DyEa5Zv3WLgqov+IxrdhhCbAaY/Y4G1Ei8FMOroyfwhrjg5 2MBsHWRvtLQ6XPUyQ9U9PAm7OPnP3yKI0q+TSk1Eo2yKaUeP5UlCwf3tdVGdTSqUKWeT 7s4WlXYjm3yAnvstbVKk7mxlxWM1p27Vt0q3ZCRkyKngzsRqL4yFIPxxjBOzShWJqCUr uy/Py3hRi46kPqdBSVqDrUbgi53g1/aUyM4GRZIzP5N/tUtSpTvIx/YQS8RB2xQhc5uy CuBw== X-Gm-Message-State: AOJu0YyKwtlbPA3TiGskpdiNDEMM0QvoPsP92dLUWl7ZCNBS1bmADVOb BAchIgoUq/ucdFS8wMiMoK8= X-Google-Smtp-Source: AGHT+IFSv+65IiQiN8WCGcLVQvQiuR6hHdW5qXQ7nf6ECXpLpXmmUxxmzvhwBggjw2vBz5nonWlXlg== X-Received: by 2002:a05:690c:3745:b0:5d8:5fad:8dcc with SMTP id fw5-20020a05690c374500b005d85fad8dccmr507589ywb.29.1701632022542; Sun, 03 Dec 2023 11:33:42 -0800 (PST) Received: from localhost ([2601:344:8301:57f0:cb98:c3e:57c:8191]) by smtp.gmail.com with ESMTPSA id m190-20020a0dfcc7000000b005463e45458bsm2765478ywf.123.2023.12.03.11.33.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 11:33:41 -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 , Bart Van Assche , Sergey Shtylyov Subject: [PATCH v2 19/35] iommu: use atomic find_bit() API where appropriate Date: Sun, 3 Dec 2023 11:32:51 -0800 Message-Id: <20231203193307.542794-18-yury.norov@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231203193307.542794-1-yury.norov@gmail.com> References: <20231203192422.539300-1-yury.norov@gmail.com> <20231203193307.542794-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-20231203_113343_417437_A479EA3D X-CRM114-Status: GOOD ( 14.31 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Switch opencoded find_and_set_next_bit() in __arm_smmu_alloc_bitmap() and msm_iommu_alloc_ctx() to use dedicated API, 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; } -- 2.40.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel