From patchwork Fri Jan 13 23:27:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 13101729 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C58AC6379F for ; Fri, 13 Jan 2023 23:27:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231454AbjAMX1e (ORCPT ); Fri, 13 Jan 2023 18:27:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231447AbjAMX1c (ORCPT ); Fri, 13 Jan 2023 18:27:32 -0500 Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAEB38CBE3 for ; Fri, 13 Jan 2023 15:27:31 -0800 (PST) Received: by mail-ot1-x332.google.com with SMTP id d2-20020a056830044200b00684cc404c8aso2515234otc.0 for ; Fri, 13 Jan 2023 15:27:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=sFVv+FTu2viKrddF8zqbqpZJ1cote5/OKzz+8VqeQLQ=; b=NyDGqZHEiXNsR528nGJqXh3t4914oG0RdRug3tiug4SCBdNwiI+d39jk60VwmMKlTG rYd/RF8R14lyCuui5gblcC7dIGV5b5Xo3OnX9IH9AxYwmiNQFy5h28cJxUc/KZF0e7wE wHjHWRcOWZfyiWVqgCj5dFpi7okTxnelvH7zxA5vwCvQUI/F6ced50dgq8fbbWTA6eJs 0xfncSKpyEFSVBGEbSZa9G2UTZLD2Z1jiDc9luBxfinqRDCkwc4chtFPURj1U9M0Lxv9 LT8U37Zi9LJOtiBW/4el65yrhxr2ScSJjOLQ06afZAT6BpQFx+0S98HCpIcppM+BLGc8 MmFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=sFVv+FTu2viKrddF8zqbqpZJ1cote5/OKzz+8VqeQLQ=; b=ENEqWmm+nBfDEiNrI3OQLq0j9hxUroI/dzSFHJPGOmyPDlvxfP85K1OREyZKF4VKd/ PKYzug8Wg0bw4XAFT4UgHzQNt4laiwJlwzDx1QbLjl45jVD6e4aM5bRbvswLureiHhFw NzLUJFWgicbIj2hpBurSZDAUXCbteFoZ8Z2k8axzko6UCIIUrS+INJfDxOkpZWT1zqzG MAHVYU23AX2kDLtORG88sXO0yYIHrIAP0ed0MrqxeTzbQy7fcXYG83eUmy9uTUM/XS2/ Dz5A0jK+3zLJVLZYcNwc3E5pmovd9Nc7bljqW504sNNl4QVWOi1Dt8AKUjkaNz0xkOPC YnLg== X-Gm-Message-State: AFqh2kpKyKPFt2QCCMCiXFmFSiP1yuDMX9DL2CBziA2xu7YeSo6avNXw y3CjGh3QIycZij1a/nD0vHE= X-Google-Smtp-Source: AMrXdXseiMVoeqJkocKLEAtCL5b7VZkM5pdXOZEKEaqlnXLek0psf9GsUGoVGSZ7D0bcrZ/ZGFfu9Q== X-Received: by 2002:a9d:61d2:0:b0:66e:a0ea:674c with SMTP id h18-20020a9d61d2000000b0066ea0ea674cmr40575268otk.1.1673652451144; Fri, 13 Jan 2023 15:27:31 -0800 (PST) Received: from rpearson-X570-AORUS-PRO-WIFI.tx.rr.com (2603-8081-140c-1a00-3f47-8433-ec70-f475.res6.spectrum.com. [2603:8081:140c:1a00:3f47:8433:ec70:f475]) by smtp.gmail.com with ESMTPSA id q13-20020a9d57cd000000b0066871c3adb3sm11297433oti.28.2023.01.13.15.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 15:27:30 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, leonro@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v3 1/6] RDMA/rxe: Cleanup mr_check_range Date: Fri, 13 Jan 2023 17:27:00 -0600 Message-Id: <20230113232704.20072-2-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230113232704.20072-1-rpearsonhpe@gmail.com> References: <20230113232704.20072-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Remove blank lines and replace EFAULT by EINVAL when an invalid mr type is used. Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_mr.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c index 072eac4b65d2..632ee1e516a1 100644 --- a/drivers/infiniband/sw/rxe/rxe_mr.c +++ b/drivers/infiniband/sw/rxe/rxe_mr.c @@ -26,8 +26,6 @@ u8 rxe_get_next_key(u32 last_key) int mr_check_range(struct rxe_mr *mr, u64 iova, size_t length) { - - switch (mr->ibmr.type) { case IB_MR_TYPE_DMA: return 0; @@ -41,7 +39,7 @@ int mr_check_range(struct rxe_mr *mr, u64 iova, size_t length) default: rxe_dbg_mr(mr, "type (%d) not supported\n", mr->ibmr.type); - return -EFAULT; + return -EINVAL; } } From patchwork Fri Jan 13 23:27:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 13101730 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDC66C3DA78 for ; Fri, 13 Jan 2023 23:27:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231184AbjAMX1g (ORCPT ); Fri, 13 Jan 2023 18:27:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229968AbjAMX1f (ORCPT ); Fri, 13 Jan 2023 18:27:35 -0500 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56CE87A397 for ; Fri, 13 Jan 2023 15:27:34 -0800 (PST) Received: by mail-ot1-x32e.google.com with SMTP id k7-20020a056830168700b0067832816190so13058449otr.1 for ; Fri, 13 Jan 2023 15:27:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=MSc+ZeVhmJVAyrOad5GEnPdKs11Mmr6EK22kGWHehxY=; b=My4hdjo2+P/Wli7csPfuJiS1HFcm6l7xxDyBN3G+4WztuyB1tugCDA65WW+np1Vohn IdXePYKYy5umoDFl7isEPca3krQ1i3SlJN4OM4lDwcS+VePodwsxUOgmvv0Q0Hlie1Xv y3vFTnmp45sp+th1Ul2P6IqheVPWbHTRh8PeN3rvEJxhE0V0z57Rh0hjQ1hW4siPowFS tp4OCTUJ4VoDU9x5QgEmAGzZjjrTtWIizyD7bzJnN/0BBZwGFQv5vy8s5Aaq2UWfGljC ZIyrpcmjmVSPjuGdZi+KSHNtIsTHllOYAm7wzIa7YDCn+DJ04hBSGZMOY/QsMfhESk7B e4lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=MSc+ZeVhmJVAyrOad5GEnPdKs11Mmr6EK22kGWHehxY=; b=uFUkoBasmmuloXEZA8bmZ2/+VUwiTzy/KssHNjkDbV1vZV2cSRdHi8UMDVu4OjCEkV BBtUKM8x4VQkfuO8F4BBqwE2h0azYWAoEvsN+ijz44oZeG2hDk9ukidC/two+nplZpHD j5E9SEkFV8e9RFREKecYHNbJglDyuw+HUxtDhQIr1Sv0L0cMuzma8eW1lv2VFTKOnXVA WhvjepqQ/EHBA0oCOP1hViabZfmx6SZEewhfg5OOEjVcOQiGE4UA6aN4ER+092+kCAMC Pjhh56SoSfxk2zw9sZidDF/WNimhJe2aN0rABbafTIqE+Mj7UGAz07z0Myzo+NjQJI00 FFUw== X-Gm-Message-State: AFqh2kr6cN9sOqPxgJ3Zv34Qc2aoPdXF44puDhS1itcVbZcsnuMiV0DX 9zz33d10g0zCTB0c24naycv3PrDTWXGq/A== X-Google-Smtp-Source: AMrXdXsYXhVRQTKqoqk0b6EnoTkQNMjty13jnPNuGEWfEe8rGLK6IZYPC1WQ6XzsidRnFMJJG8KPug== X-Received: by 2002:a9d:7748:0:b0:684:dc47:77f8 with SMTP id t8-20020a9d7748000000b00684dc4777f8mr371722otl.5.1673652453693; Fri, 13 Jan 2023 15:27:33 -0800 (PST) Received: from rpearson-X570-AORUS-PRO-WIFI.tx.rr.com (2603-8081-140c-1a00-3f47-8433-ec70-f475.res6.spectrum.com. [2603:8081:140c:1a00:3f47:8433:ec70:f475]) by smtp.gmail.com with ESMTPSA id q13-20020a9d57cd000000b0066871c3adb3sm11297433oti.28.2023.01.13.15.27.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 15:27:33 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, leonro@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v3 2/6] RDMA/rxe: Move rxe_map_mr_sg to rxe_mr.c Date: Fri, 13 Jan 2023 17:27:01 -0600 Message-Id: <20230113232704.20072-3-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230113232704.20072-1-rpearsonhpe@gmail.com> References: <20230113232704.20072-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Move rxe_map_mr_sg() to rxe_mr.c where it makes a little more sense. Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_loc.h | 2 ++ drivers/infiniband/sw/rxe/rxe_mr.c | 36 +++++++++++++++++++++++++++ drivers/infiniband/sw/rxe/rxe_verbs.c | 36 --------------------------- 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_loc.h b/drivers/infiniband/sw/rxe/rxe_loc.h index 948ce4902b10..29b6c2143045 100644 --- a/drivers/infiniband/sw/rxe/rxe_loc.h +++ b/drivers/infiniband/sw/rxe/rxe_loc.h @@ -69,6 +69,8 @@ int rxe_mr_copy(struct rxe_mr *mr, u64 iova, void *addr, int length, enum rxe_mr_copy_dir dir); int copy_data(struct rxe_pd *pd, int access, struct rxe_dma_info *dma, void *addr, int length, enum rxe_mr_copy_dir dir); +int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, + int sg_nents, unsigned int *sg_offset); void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length); struct rxe_mr *lookup_mr(struct rxe_pd *pd, int access, u32 key, enum rxe_mr_lookup_type type); diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c index 632ee1e516a1..229c7259644c 100644 --- a/drivers/infiniband/sw/rxe/rxe_mr.c +++ b/drivers/infiniband/sw/rxe/rxe_mr.c @@ -223,6 +223,42 @@ int rxe_mr_init_fast(int max_pages, struct rxe_mr *mr) return err; } +static int rxe_set_page(struct ib_mr *ibmr, u64 addr) +{ + struct rxe_mr *mr = to_rmr(ibmr); + struct rxe_map *map; + struct rxe_phys_buf *buf; + + if (unlikely(mr->nbuf == mr->num_buf)) + return -ENOMEM; + + map = mr->map[mr->nbuf / RXE_BUF_PER_MAP]; + buf = &map->buf[mr->nbuf % RXE_BUF_PER_MAP]; + + buf->addr = addr; + buf->size = ibmr->page_size; + mr->nbuf++; + + return 0; +} + +int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, + int sg_nents, unsigned int *sg_offset) +{ + struct rxe_mr *mr = to_rmr(ibmr); + int n; + + mr->nbuf = 0; + + n = ib_sg_to_pages(ibmr, sg, sg_nents, sg_offset, rxe_set_page); + + mr->page_shift = ilog2(ibmr->page_size); + mr->page_mask = ibmr->page_size - 1; + mr->offset = ibmr->iova & mr->page_mask; + + return n; +} + static void lookup_iova(struct rxe_mr *mr, u64 iova, int *m_out, int *n_out, size_t *offset_out) { diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c index 025b35bf014e..7a902e0a0607 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.c +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c @@ -948,42 +948,6 @@ static struct ib_mr *rxe_alloc_mr(struct ib_pd *ibpd, enum ib_mr_type mr_type, return ERR_PTR(err); } -static int rxe_set_page(struct ib_mr *ibmr, u64 addr) -{ - struct rxe_mr *mr = to_rmr(ibmr); - struct rxe_map *map; - struct rxe_phys_buf *buf; - - if (unlikely(mr->nbuf == mr->num_buf)) - return -ENOMEM; - - map = mr->map[mr->nbuf / RXE_BUF_PER_MAP]; - buf = &map->buf[mr->nbuf % RXE_BUF_PER_MAP]; - - buf->addr = addr; - buf->size = ibmr->page_size; - mr->nbuf++; - - return 0; -} - -static int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, - int sg_nents, unsigned int *sg_offset) -{ - struct rxe_mr *mr = to_rmr(ibmr); - int n; - - mr->nbuf = 0; - - n = ib_sg_to_pages(ibmr, sg, sg_nents, sg_offset, rxe_set_page); - - mr->page_shift = ilog2(ibmr->page_size); - mr->page_mask = ibmr->page_size - 1; - mr->offset = ibmr->iova & mr->page_mask; - - return n; -} - static ssize_t parent_show(struct device *device, struct device_attribute *attr, char *buf) { From patchwork Fri Jan 13 23:27:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 13101731 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE64BC677F1 for ; Fri, 13 Jan 2023 23:27:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231441AbjAMX1i (ORCPT ); Fri, 13 Jan 2023 18:27:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231445AbjAMX1h (ORCPT ); Fri, 13 Jan 2023 18:27:37 -0500 Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D85F8CBE3 for ; Fri, 13 Jan 2023 15:27:36 -0800 (PST) Received: by mail-ot1-x336.google.com with SMTP id p17-20020a9d6951000000b00678306ceb94so13052864oto.5 for ; Fri, 13 Jan 2023 15:27:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=doH5pfEhKyXp0YMTNNNIQAEkD7VY0qN/u2wnPS9b96M=; b=PI5AsCC2VXqqKpRm1Vb4cBQ1P5qrMVYS+GJQNk6BiF7eNSwYZPSSQFaOxoj8WmkSy/ XE/4xvQ9GFSTitHWYVWxCDlMF6RlRqkgknpB0ptu2hNcdlGTQEkA6ZkF0HQ87Cq0Hmf3 zyV41Uq6EEtiXmtU3tB5nMwff7GijpLZwqchLC6mvZ5L4AgWJ7X3BHwq0f9zsYfK+G3R k9QuOFrgsguf2Q4n6jIPZrMn1505x9lCmB1st6ghYxiIDflhyWOddt61sS5tARAnL2/s mer+znYvcluqxVOmXyXTCy2h+9OxANiQgwK0rtfOwf9dYnRlfap9dQlnkrWJiV3DZZIc mIFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=doH5pfEhKyXp0YMTNNNIQAEkD7VY0qN/u2wnPS9b96M=; b=N74QmS5C6eFdtGfkAAH9OZ95/Df2qwYaWeMkDUSChFVcHRLA7dxlSz2dKxyyTdLGXc 0kgAAhFYNiakTbHKJ2jRp0tYoqBjcwimIylrAK/338V/TXvHmZg6xe4w1LdUZGN97RcZ X3YoY7mK3+ylKJp6Yg1MQkwW701kMG6AzHqCovZ4hS2c12JprSgx7EiehqrU7RLv2N9p MAjYKWHnkJuzxMFMANgA14RJkFevgIMp8KSBV1NwjPniNZ7dPLppRsYBei/Znu4JBXxp admQ5KOZZL6zYrA+AKecC3ukBcAfuHjIEXmTkdoTGNB7M7g+A9XzUUFKDyb2/sXLl6/3 BQwA== X-Gm-Message-State: AFqh2kr8iDuOuIB7ixDZSzwIly0nXjUNmCV8Fz+BNEtgY+YSwqpwezEM uGmoBXY8PcCZXeFpqaU2uTQ= X-Google-Smtp-Source: AMrXdXtAPHsTsGBg1nKjxy6SLc/cOtXLjjT6nnKHqge9xltOzrnAAa0fckdECQa8725PtIDRVvMV8Q== X-Received: by 2002:a05:6830:698e:b0:684:c941:9e1f with SMTP id cy14-20020a056830698e00b00684c9419e1fmr3487629otb.15.1673652455861; Fri, 13 Jan 2023 15:27:35 -0800 (PST) Received: from rpearson-X570-AORUS-PRO-WIFI.tx.rr.com (2603-8081-140c-1a00-3f47-8433-ec70-f475.res6.spectrum.com. [2603:8081:140c:1a00:3f47:8433:ec70:f475]) by smtp.gmail.com with ESMTPSA id q13-20020a9d57cd000000b0066871c3adb3sm11297433oti.28.2023.01.13.15.27.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 15:27:35 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, leonro@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v3 3/6] RDMA-rxe: Isolate mr code from atomic_reply() Date: Fri, 13 Jan 2023 17:27:02 -0600 Message-Id: <20230113232704.20072-4-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230113232704.20072-1-rpearsonhpe@gmail.com> References: <20230113232704.20072-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Isolate mr specific code from atomic_reply() in rxe_resp.c into a subroutine rxe_mr_do_atomic_op() in rxe_mr.c. Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_loc.h | 2 ++ drivers/infiniband/sw/rxe/rxe_mr.c | 30 +++++++++++++++++ drivers/infiniband/sw/rxe/rxe_resp.c | 49 ++++++++-------------------- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_loc.h b/drivers/infiniband/sw/rxe/rxe_loc.h index 29b6c2143045..bcb1bbcf50df 100644 --- a/drivers/infiniband/sw/rxe/rxe_loc.h +++ b/drivers/infiniband/sw/rxe/rxe_loc.h @@ -72,6 +72,8 @@ int copy_data(struct rxe_pd *pd, int access, struct rxe_dma_info *dma, int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, int sg_nents, unsigned int *sg_offset); void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length); +int rxe_mr_do_atomic_op(struct rxe_mr *mr, u64 iova, int opcode, + u64 compare, u64 swap_add, u64 *orig_val); struct rxe_mr *lookup_mr(struct rxe_pd *pd, int access, u32 key, enum rxe_mr_lookup_type type); int mr_check_range(struct rxe_mr *mr, u64 iova, size_t length); diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c index 229c7259644c..791731be6067 100644 --- a/drivers/infiniband/sw/rxe/rxe_mr.c +++ b/drivers/infiniband/sw/rxe/rxe_mr.c @@ -538,6 +538,36 @@ int copy_data( return err; } +static DEFINE_SPINLOCK(atomic_ops_lock); + +int rxe_mr_do_atomic_op(struct rxe_mr *mr, u64 iova, int opcode, + u64 compare, u64 swap_add, u64 *orig_val) +{ + u64 *vaddr = iova_to_vaddr(mr, iova, sizeof(u64)); + u64 value; + + /* needs to match rxe_resp.c */ + if (mr->state != RXE_MR_STATE_VALID || !vaddr) + return -EFAULT; + if ((uintptr_t)vaddr & 0x7) + return -EINVAL; + + spin_lock_bh(&atomic_ops_lock); + value = *orig_val = *vaddr; + + if (opcode == IB_OPCODE_RC_COMPARE_SWAP) { + if (value == compare) + value = swap_add; + } else { + value += swap_add; + } + + *vaddr = value; + spin_unlock_bh(&atomic_ops_lock); + + return 0; +} + int advance_dma_data(struct rxe_dma_info *dma, unsigned int length) { struct rxe_sge *sge = &dma->sge[dma->cur_sge]; diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c b/drivers/infiniband/sw/rxe/rxe_resp.c index c74972244f08..02301e3f343c 100644 --- a/drivers/infiniband/sw/rxe/rxe_resp.c +++ b/drivers/infiniband/sw/rxe/rxe_resp.c @@ -725,17 +725,12 @@ static enum resp_states process_flush(struct rxe_qp *qp, return RESPST_ACKNOWLEDGE; } -/* Guarantee atomicity of atomic operations at the machine level. */ -static DEFINE_SPINLOCK(atomic_ops_lock); - static enum resp_states atomic_reply(struct rxe_qp *qp, - struct rxe_pkt_info *pkt) + struct rxe_pkt_info *pkt) { - u64 *vaddr; - enum resp_states ret; struct rxe_mr *mr = qp->resp.mr; struct resp_res *res = qp->resp.res; - u64 value; + int err; if (!res) { res = rxe_prepare_res(qp, pkt, RXE_ATOMIC_MASK); @@ -743,32 +738,16 @@ static enum resp_states atomic_reply(struct rxe_qp *qp, } if (!res->replay) { - if (mr->state != RXE_MR_STATE_VALID) { - ret = RESPST_ERR_RKEY_VIOLATION; - goto out; - } - - vaddr = iova_to_vaddr(mr, qp->resp.va + qp->resp.offset, - sizeof(u64)); - - /* check vaddr is 8 bytes aligned. */ - if (!vaddr || (uintptr_t)vaddr & 7) { - ret = RESPST_ERR_MISALIGNED_ATOMIC; - goto out; - } - - spin_lock_bh(&atomic_ops_lock); - res->atomic.orig_val = value = *vaddr; - - if (pkt->opcode == IB_OPCODE_RC_COMPARE_SWAP) { - if (value == atmeth_comp(pkt)) - value = atmeth_swap_add(pkt); - } else { - value += atmeth_swap_add(pkt); - } - - *vaddr = value; - spin_unlock_bh(&atomic_ops_lock); + u64 iova = qp->resp.va + qp->resp.offset; + + err = rxe_mr_do_atomic_op(mr, iova, pkt->opcode, + atmeth_comp(pkt), + atmeth_swap_add(pkt), + &res->atomic.orig_val); + if (err == -EINVAL) + return RESPST_ERR_MISALIGNED_ATOMIC; + else if (err) + return RESPST_ERR_RKEY_VIOLATION; qp->resp.msn++; @@ -780,9 +759,7 @@ static enum resp_states atomic_reply(struct rxe_qp *qp, qp->resp.status = IB_WC_SUCCESS; } - ret = RESPST_ACKNOWLEDGE; -out: - return ret; + return RESPST_ACKNOWLEDGE; } #ifdef CONFIG_64BIT From patchwork Fri Jan 13 23:27:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 13101732 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C161BC3DA78 for ; Fri, 13 Jan 2023 23:28:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229968AbjAMX2C (ORCPT ); Fri, 13 Jan 2023 18:28:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231445AbjAMX2B (ORCPT ); Fri, 13 Jan 2023 18:28:01 -0500 Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 730037A397 for ; Fri, 13 Jan 2023 15:28:00 -0800 (PST) Received: by mail-ot1-x335.google.com with SMTP id i26-20020a9d68da000000b00672301a1664so13057050oto.6 for ; Fri, 13 Jan 2023 15:28:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=C9wMGObKT8LqdYGdJxfp6Pi1vT8lU038I/3cKeDppoE=; b=DuY+RfSco8zei/9qAyYekMe4GDNwqF132J5PWnaj+DgL9Xfu0uOTa4uu7RL1/+od77 b8kndQ9X5tBm+yo03Ivrze6wyinCMlNdp+AX/SBuszuPzFgaUHYHbxwmtu+33znjE8O5 1EHEl6u9k+1jXrjGPPS1Xf4JcHhJA72FbZIVY6BZfp7GUEoY56Wf4spXsdhUnA67ft/m qCQYnnqyjq+vZ7N3sZffKyj3BpzIEpD85khMEMkHh/q0aM6bBdEFiS+F0RLyXsSCsYCs QFYyedihULiTrZYi9A3NaP/bhXYAPtoGBmTxVPeowiCgMiMvRIDpa+hvhjXTZmNI8pbS KK4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=C9wMGObKT8LqdYGdJxfp6Pi1vT8lU038I/3cKeDppoE=; b=7KRWnfm/71ux55wYGBvNC4XjE0/O9fBGJ+eB0djI0ngVjZbi6bZzh6Icegm0j1XJ7C g1zBuvb6OnmVKde49G6ZPFDSfTam9R//4sCCT5KxYOfNHb/G7uhNhivdUKnp/4eh2xAn KsZzh1OdcY3ENHsURWkknesTMVs2BxCLz033MqEj+JnLwaXMmZ5mljqv37S7n4pauRLl y8IPTLWbOvcE59uPXFm4VoroOsKxK3ASHB9V7bxjUJ5JqG/tFuV9kQBF6fKpOt56Ov6o kztVKJlYXKSY4T9UaEAjLXpNYS2iixP91takQ2KdaD0l4Aq95cNdwMKwLrWBzMU3iNAK QBVw== X-Gm-Message-State: AFqh2kqV/600lG100vAgVDQ/q3lfK3Qv1eoss6tBXwwtUs63X1EjhnCL YxvCgthoMe0NJ1e6SKNL5xQ= X-Google-Smtp-Source: AMrXdXsesoDjljT514r4W7Ot68qy6CE1d7XisNAwAVa798ubT7gPcsZXU1qfWUlBLroCzl7y5BDclw== X-Received: by 2002:a05:6830:6209:b0:661:dfeb:a95e with SMTP id cd9-20020a056830620900b00661dfeba95emr7760569otb.9.1673652479847; Fri, 13 Jan 2023 15:27:59 -0800 (PST) Received: from rpearson-X570-AORUS-PRO-WIFI.tx.rr.com (2603-8081-140c-1a00-3f47-8433-ec70-f475.res6.spectrum.com. [2603:8081:140c:1a00:3f47:8433:ec70:f475]) by smtp.gmail.com with ESMTPSA id q13-20020a9d57cd000000b0066871c3adb3sm11297433oti.28.2023.01.13.15.27.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 15:27:59 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, leonro@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v3 4/6] RDMA-rxe: Isolate mr code from atomic_write_reply() Date: Fri, 13 Jan 2023 17:27:04 -0600 Message-Id: <20230113232704.20072-5-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230113232704.20072-1-rpearsonhpe@gmail.com> References: <20230113232704.20072-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Isolate mr specific code from atomic_write_reply() in rxe_resp.c into a subroutine rxe_mr_do_atomic_write() in rxe_mr.c. Check length for atomic write operation. Make iova_to_vaddr() static. Signed-off-by: Bob Pearson --- v3: Fixed bug reported by kernel test robot. Ifdef'ed out atomic 8 byte write if CONFIG_64BIT is not defined as orignally intended by the developers of the atomic write implementation. link: https://lore.kernel.org/linux-rdma/202301131143.CmoyVcul-lkp@intel.com/ drivers/infiniband/sw/rxe/rxe_loc.h | 1 + drivers/infiniband/sw/rxe/rxe_mr.c | 50 ++++++++++++++++++++++++ drivers/infiniband/sw/rxe/rxe_resp.c | 58 +++++++++++----------------- 3 files changed, 73 insertions(+), 36 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_loc.h b/drivers/infiniband/sw/rxe/rxe_loc.h index bcb1bbcf50df..fd70c71a9e4e 100644 --- a/drivers/infiniband/sw/rxe/rxe_loc.h +++ b/drivers/infiniband/sw/rxe/rxe_loc.h @@ -74,6 +74,7 @@ int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length); int rxe_mr_do_atomic_op(struct rxe_mr *mr, u64 iova, int opcode, u64 compare, u64 swap_add, u64 *orig_val); +int rxe_mr_do_atomic_write(struct rxe_mr *mr, u64 iova, void *addr); struct rxe_mr *lookup_mr(struct rxe_pd *pd, int access, u32 key, enum rxe_mr_lookup_type type); int mr_check_range(struct rxe_mr *mr, u64 iova, size_t length); diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c index 791731be6067..1e74f5e8e10b 100644 --- a/drivers/infiniband/sw/rxe/rxe_mr.c +++ b/drivers/infiniband/sw/rxe/rxe_mr.c @@ -568,6 +568,56 @@ int rxe_mr_do_atomic_op(struct rxe_mr *mr, u64 iova, int opcode, return 0; } +/** + * rxe_mr_do_atomic_write() - write 64bit value to iova from addr + * @mr: memory region + * @iova: iova in mr + * @addr: source of data to write + * + * Returns: + * 0 on success + * -1 for misaligned address + * -2 for access errors + * -3 for cpu without native 64 bit support + */ +int rxe_mr_do_atomic_write(struct rxe_mr *mr, u64 iova, void *addr) +{ +#if defined CONFIG_64BIT + u64 *vaddr; + u64 value; + unsigned int length = 8; + + /* See IBA oA19-28 */ + if (unlikely(mr->state != RXE_MR_STATE_VALID)) { + rxe_dbg_mr(mr, "mr not valid"); + return -2; + } + + /* See IBA A19.4.2 */ + if (unlikely((uintptr_t)vaddr & 0x7 || iova & 0x7)) { + rxe_dbg_mr(mr, "misaligned address"); + return -1; + } + + vaddr = iova_to_vaddr(mr, iova, length); + if (unlikely(!vaddr)) { + rxe_dbg_mr(mr, "iova out of range"); + return -2; + } + + /* this makes no sense. What of payload is not 8? */ + memcpy(&value, addr, length); + + /* Do atomic write after all prior operations have completed */ + smp_store_release(vaddr, value); + + return 0; +#else + rxe_dbg_mr(mr, "64 bit integers not atomic"); + return -3; +#endif +} + int advance_dma_data(struct rxe_dma_info *dma, unsigned int length) { struct rxe_sge *sge = &dma->sge[dma->cur_sge]; diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c b/drivers/infiniband/sw/rxe/rxe_resp.c index 02301e3f343c..1083cda22c65 100644 --- a/drivers/infiniband/sw/rxe/rxe_resp.c +++ b/drivers/infiniband/sw/rxe/rxe_resp.c @@ -762,26 +762,33 @@ static enum resp_states atomic_reply(struct rxe_qp *qp, return RESPST_ACKNOWLEDGE; } -#ifdef CONFIG_64BIT -static enum resp_states do_atomic_write(struct rxe_qp *qp, - struct rxe_pkt_info *pkt) +static enum resp_states atomic_write_reply(struct rxe_qp *qp, + struct rxe_pkt_info *pkt) { + u64 iova = qp->resp.va + qp->resp.offset; + struct resp_res *res = qp->resp.res; struct rxe_mr *mr = qp->resp.mr; + void *addr = payload_addr(pkt); int payload = payload_size(pkt); - u64 src, *dst; - - if (mr->state != RXE_MR_STATE_VALID) - return RESPST_ERR_RKEY_VIOLATION; + int err; - memcpy(&src, payload_addr(pkt), payload); + if (!res) { + res = rxe_prepare_res(qp, pkt, RXE_ATOMIC_WRITE_MASK); + qp->resp.res = res; + } - dst = iova_to_vaddr(mr, qp->resp.va + qp->resp.offset, payload); - /* check vaddr is 8 bytes aligned. */ - if (!dst || (uintptr_t)dst & 7) - return RESPST_ERR_MISALIGNED_ATOMIC; + if (res->replay) + return RESPST_ACKNOWLEDGE; - /* Do atomic write after all prior operations have completed */ - smp_store_release(dst, src); + err = rxe_mr_do_atomic_write(mr, iova, addr); + if (unlikely(err)) { + if (err == -3) + return RESPST_ERR_UNSUPPORTED_OPCODE; + else if (err == -2) + return RESPST_ERR_RKEY_VIOLATION; + else + return RESPST_ERR_MISALIGNED_ATOMIC; + } /* decrease resp.resid to zero */ qp->resp.resid -= sizeof(payload); @@ -794,29 +801,8 @@ static enum resp_states do_atomic_write(struct rxe_qp *qp, qp->resp.opcode = pkt->opcode; qp->resp.status = IB_WC_SUCCESS; - return RESPST_ACKNOWLEDGE; -} -#else -static enum resp_states do_atomic_write(struct rxe_qp *qp, - struct rxe_pkt_info *pkt) -{ - return RESPST_ERR_UNSUPPORTED_OPCODE; -} -#endif /* CONFIG_64BIT */ - -static enum resp_states atomic_write_reply(struct rxe_qp *qp, - struct rxe_pkt_info *pkt) -{ - struct resp_res *res = qp->resp.res; - if (!res) { - res = rxe_prepare_res(qp, pkt, RXE_ATOMIC_WRITE_MASK); - qp->resp.res = res; - } - - if (res->replay) - return RESPST_ACKNOWLEDGE; - return do_atomic_write(qp, pkt); + return RESPST_ACKNOWLEDGE; } static struct sk_buff *prepare_ack_packet(struct rxe_qp *qp, From patchwork Fri Jan 13 23:27:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 13101733 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34B0DC6379F for ; Fri, 13 Jan 2023 23:28:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229870AbjAMX2H (ORCPT ); Fri, 13 Jan 2023 18:28:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231445AbjAMX2F (ORCPT ); Fri, 13 Jan 2023 18:28:05 -0500 Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CE128CBF2 for ; Fri, 13 Jan 2023 15:28:05 -0800 (PST) Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-15eeec85280so2817096fac.11 for ; Fri, 13 Jan 2023 15:28:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=xVD4hXw6D0oLF7hPL29BBmRza9euKRPXQEHZZZmWvOw=; b=koFgt9L2AG4w57NJcD+oGkhUooIIggW/c2toEaSsLIcJXdhYRrcjnLrZrwkIpNb0Af QWp6U+JsAZTLOciJwXDqKuRP+E9/znpx+a3CM2WVrQnkurTPvxLj1ZKO19VfkKu8pv1i yiuuIrXUOWZycQHSGi6MTq4PaVu8LZnjbrxoR2lLw3vkApbieGxRiTkuoFio2pIqO9cT Gr5tBvm5d7dlkojmE36MPF4/lo0Tz0zqgfL65AqzAXmyT6LGHxPhZpitFd8v/cQdh/Zy yd+x81JI3BLggIXM4y4KlrC7goc1EIfOfUBU+D/FZ2cNeuSFm/SnZAVrsurk2P4ExxVd Dp0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=xVD4hXw6D0oLF7hPL29BBmRza9euKRPXQEHZZZmWvOw=; b=aSyE885vki9D7MhUxGM62MJpevdUFMOeG54I/aylaEch1jt42k93wA91462VcvyaBr qMye6kCv8A6rJKmsUjDo+31xuBlqRU9GPpJKE+6cp1ZC8of9YngfodJ+hzxqbVkbBi23 mEaHfbzHhrQiTZmhHmJq5yGuhMhPbWobwdU2ky8iciTyOVRJFxi0QHQizcTR/vYaskg2 f4/IbqRMj+RTjvFmbVjgCE7wuaiGv1SDUMo8u5BLEVTtS10mVdtT5ZfVN4d+yj8wIYvD JB+wCmQc3wh+a8W9SfPjzQO5/J4dF7AgJU3NnhVZvIp7yHCzJl/h/jUjD5i/u5NrvmQh uEyw== X-Gm-Message-State: AFqh2kpDEUEsrzRNfIqewNthgAJ2UOx7sEc0xeF6MXL4aP7XmGiWbcAz tOIMmnPRHNc65pr0mVCPjcM= X-Google-Smtp-Source: AMrXdXu5pUkgQlhk0RGacHuEqZTrNydZZvrfEFKgSXKjNubFNE+dp3Wk8D/ralyoSFOe4+cZ2QghqA== X-Received: by 2002:a05:6870:f705:b0:14f:e8c0:3cdf with SMTP id ej5-20020a056870f70500b0014fe8c03cdfmr31566782oab.5.1673652484436; Fri, 13 Jan 2023 15:28:04 -0800 (PST) Received: from rpearson-X570-AORUS-PRO-WIFI.tx.rr.com (2603-8081-140c-1a00-3f47-8433-ec70-f475.res6.spectrum.com. [2603:8081:140c:1a00:3f47:8433:ec70:f475]) by smtp.gmail.com with ESMTPSA id q13-20020a9d57cd000000b0066871c3adb3sm11297433oti.28.2023.01.13.15.28.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 15:28:04 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, leonro@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v3 5/6] RDMA/rxe: Cleanup page variables in rxe_mr.c Date: Fri, 13 Jan 2023 17:27:05 -0600 Message-Id: <20230113232704.20072-6-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230113232704.20072-1-rpearsonhpe@gmail.com> References: <20230113232704.20072-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Cleanup usage of mr->page_shift and mr->page_mask and introduce an extractor for mr->ibmr.page_size. Normal usage in the kernel has page_mask masking out offset in page rather than masking out the page number. The rxe driver had reversed that which was confusing. Implicitly there can be a per mr page_size which was not uniformly supported. Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_mr.c | 31 ++++++++++++--------------- drivers/infiniband/sw/rxe/rxe_verbs.h | 11 +++++++--- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c index 1e74f5e8e10b..fd5537ee7f04 100644 --- a/drivers/infiniband/sw/rxe/rxe_mr.c +++ b/drivers/infiniband/sw/rxe/rxe_mr.c @@ -60,6 +60,9 @@ static void rxe_mr_init(int access, struct rxe_mr *mr) mr->lkey = mr->ibmr.lkey = lkey; mr->rkey = mr->ibmr.rkey = rkey; + mr->ibmr.page_size = PAGE_SIZE; + mr->page_mask = PAGE_MASK; + mr->page_shift = PAGE_SHIFT; mr->state = RXE_MR_STATE_INVALID; } @@ -149,9 +152,6 @@ int rxe_mr_init_user(struct rxe_dev *rxe, u64 start, u64 length, u64 iova, goto err_release_umem; } - mr->page_shift = PAGE_SHIFT; - mr->page_mask = PAGE_SIZE - 1; - num_buf = 0; map = mr->map; if (length > 0) { @@ -180,7 +180,7 @@ int rxe_mr_init_user(struct rxe_dev *rxe, u64 start, u64 length, u64 iova, goto err_release_umem; } buf->addr = (uintptr_t)vaddr; - buf->size = PAGE_SIZE; + buf->size = mr_page_size(mr); num_buf++; buf++; @@ -189,10 +189,9 @@ int rxe_mr_init_user(struct rxe_dev *rxe, u64 start, u64 length, u64 iova, mr->umem = umem; mr->access = access; - mr->offset = ib_umem_offset(umem); + mr->page_offset = ib_umem_offset(umem); mr->state = RXE_MR_STATE_VALID; mr->ibmr.type = IB_MR_TYPE_USER; - mr->ibmr.page_size = PAGE_SIZE; return 0; @@ -246,29 +245,27 @@ int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, int sg_nents, unsigned int *sg_offset) { struct rxe_mr *mr = to_rmr(ibmr); - int n; - - mr->nbuf = 0; + unsigned int page_size = mr_page_size(mr); - n = ib_sg_to_pages(ibmr, sg, sg_nents, sg_offset, rxe_set_page); + mr->page_shift = ilog2(page_size); + mr->page_mask = ~((u64)page_size - 1); + mr->page_offset = ibmr->iova & (page_size - 1); - mr->page_shift = ilog2(ibmr->page_size); - mr->page_mask = ibmr->page_size - 1; - mr->offset = ibmr->iova & mr->page_mask; + mr->nbuf = 0; - return n; + return ib_sg_to_pages(ibmr, sg, sg_nents, sg_offset, rxe_set_page); } static void lookup_iova(struct rxe_mr *mr, u64 iova, int *m_out, int *n_out, size_t *offset_out) { - size_t offset = iova - mr->ibmr.iova + mr->offset; + size_t offset = iova - mr->ibmr.iova + mr->page_offset; int map_index; int buf_index; u64 length; if (likely(mr->page_shift)) { - *offset_out = offset & mr->page_mask; + *offset_out = offset & (mr_page_size(mr) - 1); offset >>= mr->page_shift; *n_out = offset & mr->map_mask; *m_out = offset >> mr->map_shift; @@ -342,7 +339,7 @@ int rxe_flush_pmem_iova(struct rxe_mr *mr, u64 iova, int length) if (mr->ibmr.type == IB_MR_TYPE_DMA) return -EFAULT; - offset = (iova - mr->ibmr.iova + mr->offset) & mr->page_mask; + offset = (iova - mr->ibmr.iova + mr->page_offset) & mr->page_mask; while (length > 0) { u8 *va; int bytes; diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h b/drivers/infiniband/sw/rxe/rxe_verbs.h index 19ddfa890480..bfc94caaeec5 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.h +++ b/drivers/infiniband/sw/rxe/rxe_verbs.h @@ -310,11 +310,11 @@ struct rxe_mr { u32 lkey; u32 rkey; enum rxe_mr_state state; - u32 offset; int access; - int page_shift; - int page_mask; + unsigned int page_offset; + unsigned int page_shift; + u64 page_mask; int map_shift; int map_mask; @@ -329,6 +329,11 @@ struct rxe_mr { struct rxe_map **map; }; +static inline unsigned int mr_page_size(struct rxe_mr *mr) +{ + return mr ? mr->ibmr.page_size : PAGE_SIZE; +} + enum rxe_mw_state { RXE_MW_STATE_INVALID = RXE_MR_STATE_INVALID, RXE_MW_STATE_FREE = RXE_MR_STATE_FREE, From patchwork Fri Jan 13 23:27:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Pearson X-Patchwork-Id: 13101734 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8921C3DA78 for ; Fri, 13 Jan 2023 23:28:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231448AbjAMX2N (ORCPT ); Fri, 13 Jan 2023 18:28:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231214AbjAMX2M (ORCPT ); Fri, 13 Jan 2023 18:28:12 -0500 Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B6058A211 for ; Fri, 13 Jan 2023 15:28:10 -0800 (PST) Received: by mail-ot1-x336.google.com with SMTP id f88-20020a9d03e1000000b00684c4041ff1so3351689otf.8 for ; Fri, 13 Jan 2023 15:28:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=yuUJHhird38rrcbSnnnT+JUzs9dZBnHh/e6yBr8B0G8=; b=YTymKDkAYDbmFl5qC9Org+7MSRIoq+cAA+RMrqxlfznPfAZJihnT/OGQ+4+gSWtSjf VpC2IE/zJM591V9xeViaGTbROe3RSIjtdILJ0Ez7Riym60k4UI56ARJ5MvaBIZWbPXbo 25B+OrIGZXyGFWJqZCz2ysJzw26Y7I2+yRYN1Zudn7eQUIfuS01fMJK2YkpMJwqjPwr2 Im96iKs9im+mYUKLFgWaLB0XeaToS8EAPppR6FFE2lkBqm+1LnUY7n3qKEPUVKP1JhuI UjguenK9z5oUyRdDJ+ejC5gjrniqp8ZrswKjBOYr5+k4cRvAVLpnsAP38xNZtRelP3Rr RGmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=yuUJHhird38rrcbSnnnT+JUzs9dZBnHh/e6yBr8B0G8=; b=IwEOUniA6HLRqI8rkiNjwNMLsQydRlKfKggmcQWJPdtzqOSQcD3ea0Lid7uQrmSPVI C9CvEe18PQTz8X9OA/nRRgex3aQdN5YNn/hNyEvgCr1xPdTOveR34IAwVItUEChuJDiL v6bJa1okgetCZSrbFa7RvO/kKH2ZKM0JWaS/mJLTVBQH1CVtF25Lz1WSePR8K8KCDlQM 9jJGHPQtM+KJE7plM1+eTlVlrL+HWYeDIlP0Q8/Ljfn7txOe060moUdRehqfGwOP/Uum 7tdpIIcmG6EC07kmeUZ5yhMHr280RikDJ6vL4OwKX7IBnodb+QBiw3m/KU0okKXedSFs zq3Q== X-Gm-Message-State: AFqh2krS0EvHyJIPvcKrOSxTUTxiuHICDSKsLonTzMceur9sxcPWWZxp MSjZSRlyfECbW/gXCaaLcxQ= X-Google-Smtp-Source: AMrXdXtm5yQx644M5h8ecy5r+17Omr59D/HYWJVDmc5m/MBYo0+befqAIaQ6CipWyFrUj4MIp0ImYQ== X-Received: by 2002:a9d:64c2:0:b0:670:74de:ed3e with SMTP id n2-20020a9d64c2000000b0067074deed3emr37442660otl.16.1673652489304; Fri, 13 Jan 2023 15:28:09 -0800 (PST) Received: from rpearson-X570-AORUS-PRO-WIFI.tx.rr.com (2603-8081-140c-1a00-3f47-8433-ec70-f475.res6.spectrum.com. [2603:8081:140c:1a00:3f47:8433:ec70:f475]) by smtp.gmail.com with ESMTPSA id q13-20020a9d57cd000000b0066871c3adb3sm11297433oti.28.2023.01.13.15.28.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Jan 2023 15:28:08 -0800 (PST) From: Bob Pearson To: jgg@nvidia.com, leonro@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org Cc: Bob Pearson Subject: [PATCH for-next v3 6/6] RDMA/rxe: Replace rxe_map and rxe_phys_buf by xarray Date: Fri, 13 Jan 2023 17:27:06 -0600 Message-Id: <20230113232704.20072-7-rpearsonhpe@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230113232704.20072-1-rpearsonhpe@gmail.com> References: <20230113232704.20072-1-rpearsonhpe@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Replace struct rxe-phys_buf and struct rxe_map by struct xarray in rxe_verbs.h. This allows using rcu locking on reads for the memory maps stored in each mr. This is based off of a sketch of a patch from Jason Gunthorpe in the link below. Some changes were needed to make this work. It applies cleanly to the current for-next and passes the pyverbs, perftest and the same blktests test cases which run today. Link: https://lore.kernel.org/linux-rdma/Y3gvZr6%2FNCii9Avy@nvidia.com/ Co-developed-by: Jason Gunthorpe Signed-off-by: Bob Pearson --- drivers/infiniband/sw/rxe/rxe_loc.h | 1 - drivers/infiniband/sw/rxe/rxe_mr.c | 533 ++++++++++++-------------- drivers/infiniband/sw/rxe/rxe_resp.c | 2 +- drivers/infiniband/sw/rxe/rxe_verbs.h | 21 +- 4 files changed, 251 insertions(+), 306 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_loc.h b/drivers/infiniband/sw/rxe/rxe_loc.h index fd70c71a9e4e..0cf78f9bb27c 100644 --- a/drivers/infiniband/sw/rxe/rxe_loc.h +++ b/drivers/infiniband/sw/rxe/rxe_loc.h @@ -71,7 +71,6 @@ int copy_data(struct rxe_pd *pd, int access, struct rxe_dma_info *dma, void *addr, int length, enum rxe_mr_copy_dir dir); int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, int sg_nents, unsigned int *sg_offset); -void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length); int rxe_mr_do_atomic_op(struct rxe_mr *mr, u64 iova, int opcode, u64 compare, u64 swap_add, u64 *orig_val); int rxe_mr_do_atomic_write(struct rxe_mr *mr, u64 iova, void *addr); diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c index fd5537ee7f04..e4634279080a 100644 --- a/drivers/infiniband/sw/rxe/rxe_mr.c +++ b/drivers/infiniband/sw/rxe/rxe_mr.c @@ -60,145 +60,113 @@ static void rxe_mr_init(int access, struct rxe_mr *mr) mr->lkey = mr->ibmr.lkey = lkey; mr->rkey = mr->ibmr.rkey = rkey; + mr->access = access; mr->ibmr.page_size = PAGE_SIZE; mr->page_mask = PAGE_MASK; mr->page_shift = PAGE_SHIFT; mr->state = RXE_MR_STATE_INVALID; } -static int rxe_mr_alloc(struct rxe_mr *mr, int num_buf) -{ - int i; - int num_map; - struct rxe_map **map = mr->map; - - num_map = (num_buf + RXE_BUF_PER_MAP - 1) / RXE_BUF_PER_MAP; - - mr->map = kmalloc_array(num_map, sizeof(*map), GFP_KERNEL); - if (!mr->map) - goto err1; - - for (i = 0; i < num_map; i++) { - mr->map[i] = kmalloc(sizeof(**map), GFP_KERNEL); - if (!mr->map[i]) - goto err2; - } - - BUILD_BUG_ON(!is_power_of_2(RXE_BUF_PER_MAP)); - - mr->map_shift = ilog2(RXE_BUF_PER_MAP); - mr->map_mask = RXE_BUF_PER_MAP - 1; - - mr->num_buf = num_buf; - mr->num_map = num_map; - mr->max_buf = num_map * RXE_BUF_PER_MAP; - - return 0; - -err2: - for (i--; i >= 0; i--) - kfree(mr->map[i]); - - kfree(mr->map); - mr->map = NULL; -err1: - return -ENOMEM; -} - void rxe_mr_init_dma(int access, struct rxe_mr *mr) { rxe_mr_init(access, mr); - mr->access = access; mr->state = RXE_MR_STATE_VALID; mr->ibmr.type = IB_MR_TYPE_DMA; } -static bool is_pmem_page(struct page *pg) +static unsigned long rxe_mr_iova_to_index(struct rxe_mr *mr, u64 iova) { - unsigned long paddr = page_to_phys(pg); + return (iova >> mr->page_shift) - (mr->ibmr.iova >> mr->page_shift); +} - return REGION_INTERSECTS == - region_intersects(paddr, PAGE_SIZE, IORESOURCE_MEM, - IORES_DESC_PERSISTENT_MEMORY); +static unsigned long rxe_mr_iova_to_page_offset(struct rxe_mr *mr, u64 iova) +{ + return iova & (mr_page_size(mr) - 1); +} + +static int rxe_mr_fill_pages_from_sgt(struct rxe_mr *mr, struct sg_table *sgt) +{ + XA_STATE(xas, &mr->pages, 0); + struct sg_page_iter sg_iter; + + xa_init(&mr->pages); + + __sg_page_iter_start(&sg_iter, sgt->sgl, sgt->orig_nents, 0); + if (!__sg_page_iter_next(&sg_iter)) + return 0; + + do { + xas_lock(&xas); + while (true) { + xas_store(&xas, sg_page_iter_page(&sg_iter)); + if (xas_error(&xas)) + break; + xas_next(&xas); + if (!__sg_page_iter_next(&sg_iter)) + break; + } + xas_unlock(&xas); + } while (xas_nomem(&xas, GFP_KERNEL)); + + return xas_error(&xas); } int rxe_mr_init_user(struct rxe_dev *rxe, u64 start, u64 length, u64 iova, int access, struct rxe_mr *mr) { - struct rxe_map **map; - struct rxe_phys_buf *buf = NULL; - struct ib_umem *umem; - struct sg_page_iter sg_iter; - int num_buf; - void *vaddr; + struct ib_umem *umem; int err; + rxe_mr_init(access, mr); + umem = ib_umem_get(&rxe->ib_dev, start, length, access); if (IS_ERR(umem)) { rxe_dbg_mr(mr, "Unable to pin memory region err = %d\n", (int)PTR_ERR(umem)); - err = PTR_ERR(umem); - goto err_out; + return PTR_ERR(umem); } - num_buf = ib_umem_num_pages(umem); - - rxe_mr_init(access, mr); - - err = rxe_mr_alloc(mr, num_buf); + err = rxe_mr_fill_pages_from_sgt(mr, &umem->sgt_append.sgt); if (err) { - rxe_dbg_mr(mr, "Unable to allocate memory for map\n"); - goto err_release_umem; + ib_umem_release(umem); + return err; } - num_buf = 0; - map = mr->map; - if (length > 0) { - bool persistent_access = access & IB_ACCESS_FLUSH_PERSISTENT; - - buf = map[0]->buf; - for_each_sgtable_page (&umem->sgt_append.sgt, &sg_iter, 0) { - struct page *pg = sg_page_iter_page(&sg_iter); + mr->umem = umem; + mr->ibmr.type = IB_MR_TYPE_USER; + mr->state = RXE_MR_STATE_VALID; - if (persistent_access && !is_pmem_page(pg)) { - rxe_dbg_mr(mr, "Unable to register persistent access to non-pmem device\n"); - err = -EINVAL; - goto err_release_umem; - } + return 0; +} - if (num_buf >= RXE_BUF_PER_MAP) { - map++; - buf = map[0]->buf; - num_buf = 0; - } +static int rxe_mr_alloc(struct rxe_mr *mr, int num_buf) +{ + XA_STATE(xas, &mr->pages, 0); + int i = 0; + int err; - vaddr = page_address(pg); - if (!vaddr) { - rxe_dbg_mr(mr, "Unable to get virtual address\n"); - err = -ENOMEM; - goto err_release_umem; - } - buf->addr = (uintptr_t)vaddr; - buf->size = mr_page_size(mr); - num_buf++; - buf++; + xa_init(&mr->pages); + do { + xas_lock(&xas); + while (i != num_buf) { + xas_store(&xas, XA_ZERO_ENTRY); + if (xas_error(&xas)) + break; + xas_next(&xas); + i++; } - } + xas_unlock(&xas); + } while (xas_nomem(&xas, GFP_KERNEL)); - mr->umem = umem; - mr->access = access; - mr->page_offset = ib_umem_offset(umem); - mr->state = RXE_MR_STATE_VALID; - mr->ibmr.type = IB_MR_TYPE_USER; + err = xas_error(&xas); + if (err) + return err; - return 0; + mr->num_buf = num_buf; -err_release_umem: - ib_umem_release(umem); -err_out: - return err; + return 0; } int rxe_mr_init_fast(int max_pages, struct rxe_mr *mr) @@ -212,7 +180,6 @@ int rxe_mr_init_fast(int max_pages, struct rxe_mr *mr) if (err) goto err1; - mr->max_buf = max_pages; mr->state = RXE_MR_STATE_FREE; mr->ibmr.type = IB_MR_TYPE_MEM_REG; @@ -222,116 +189,100 @@ int rxe_mr_init_fast(int max_pages, struct rxe_mr *mr) return err; } -static int rxe_set_page(struct ib_mr *ibmr, u64 addr) +static int rxe_set_page(struct ib_mr *ibmr, u64 iova) { struct rxe_mr *mr = to_rmr(ibmr); - struct rxe_map *map; - struct rxe_phys_buf *buf; + struct page *page = virt_to_page(iova & mr->page_mask); + XA_STATE(xas, &mr->pages, mr->nbuf); + int err; if (unlikely(mr->nbuf == mr->num_buf)) return -ENOMEM; - map = mr->map[mr->nbuf / RXE_BUF_PER_MAP]; - buf = &map->buf[mr->nbuf % RXE_BUF_PER_MAP]; + do { + xas_lock(&xas); + xas_store(&xas, page); + xas_unlock(&xas); + } while (xas_nomem(&xas, GFP_KERNEL)); - buf->addr = addr; - buf->size = ibmr->page_size; - mr->nbuf++; + err = xas_error(&xas); + if (err) + return err; + mr->nbuf++; return 0; } -int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, +int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sgl, int sg_nents, unsigned int *sg_offset) { struct rxe_mr *mr = to_rmr(ibmr); unsigned int page_size = mr_page_size(mr); + mr->nbuf = 0; mr->page_shift = ilog2(page_size); mr->page_mask = ~((u64)page_size - 1); - mr->page_offset = ibmr->iova & (page_size - 1); + mr->page_offset = mr->ibmr.iova & (page_size - 1); - mr->nbuf = 0; - - return ib_sg_to_pages(ibmr, sg, sg_nents, sg_offset, rxe_set_page); + return ib_sg_to_pages(ibmr, sgl, sg_nents, sg_offset, rxe_set_page); } -static void lookup_iova(struct rxe_mr *mr, u64 iova, int *m_out, int *n_out, - size_t *offset_out) -{ - size_t offset = iova - mr->ibmr.iova + mr->page_offset; - int map_index; - int buf_index; - u64 length; - - if (likely(mr->page_shift)) { - *offset_out = offset & (mr_page_size(mr) - 1); - offset >>= mr->page_shift; - *n_out = offset & mr->map_mask; - *m_out = offset >> mr->map_shift; - } else { - map_index = 0; - buf_index = 0; - - length = mr->map[map_index]->buf[buf_index].size; - - while (offset >= length) { - offset -= length; - buf_index++; - - if (buf_index == RXE_BUF_PER_MAP) { - map_index++; - buf_index = 0; - } - length = mr->map[map_index]->buf[buf_index].size; - } - - *m_out = map_index; - *n_out = buf_index; - *offset_out = offset; - } -} - -void *iova_to_vaddr(struct rxe_mr *mr, u64 iova, int length) +/* + * TODO: Attempting to modify the mr page map between the time + * a packet is received and the map is referenced as here + * in xa_load(&mr->pages) will cause problems. It is OK to + * deregister the mr since the mr reference counts will preserve + * it until memory accesses are complete. Currently reregister mr + * operations are not supported by the rxe driver but could be + * in the future. Invalidate followed by fast_reg mr will change + * the map and then the rkey so delayed packets arriving in the + * middle could use the wrong map entries. This isn't new but was + * already the case in the earlier implementation. This won't be + * a problem for well behaved programs which wait until all the + * outstanding packets for the first FMR before remapping to the + * second. + */ +static int rxe_mr_copy_xarray(struct rxe_mr *mr, void *addr, + unsigned long index, + unsigned int page_offset, unsigned int length, + enum rxe_mr_copy_dir dir) { - size_t offset; - int m, n; - void *addr; - - if (mr->state != RXE_MR_STATE_VALID) { - rxe_dbg_mr(mr, "Not in valid state\n"); - addr = NULL; - goto out; - } - - if (!mr->map) { - addr = (void *)(uintptr_t)iova; - goto out; - } + struct page *page; + unsigned int bytes; + void *va; - if (mr_check_range(mr, iova, length)) { - rxe_dbg_mr(mr, "Range violation\n"); - addr = NULL; - goto out; - } - - lookup_iova(mr, iova, &m, &n, &offset); - - if (offset + length > mr->map[m]->buf[n].size) { - rxe_dbg_mr(mr, "Crosses page boundary\n"); - addr = NULL; - goto out; + while (length) { + page = xa_load(&mr->pages, index); + if (WARN_ON(!page)) + return -EINVAL; + + bytes = min_t(unsigned int, length, + mr_page_size(mr) - page_offset); + va = kmap_local_page(page); + if (dir == RXE_FROM_MR_OBJ) + memcpy(addr, va + page_offset, bytes); + else + memcpy(va + page_offset, addr, bytes); + kunmap_local(va); + + page_offset = 0; + addr += bytes; + length -= bytes; + index++; } - addr = (void *)(uintptr_t)mr->map[m]->buf[n].addr + offset; - -out: - return addr; + return 0; } +// TODO convert iova to va through xarray and then flush int rxe_flush_pmem_iova(struct rxe_mr *mr, u64 iova, int length) { - size_t offset; + unsigned int page_offset; + unsigned long index; + struct page *page; + int bytes; + int err; + u8 *va; if (length == 0) return 0; @@ -339,104 +290,84 @@ int rxe_flush_pmem_iova(struct rxe_mr *mr, u64 iova, int length) if (mr->ibmr.type == IB_MR_TYPE_DMA) return -EFAULT; - offset = (iova - mr->ibmr.iova + mr->page_offset) & mr->page_mask; - while (length > 0) { - u8 *va; - int bytes; + err = mr_check_range(mr, iova, length); + if (err) + return err; - bytes = mr->ibmr.page_size - offset; + while (length > 0) { + page_offset = rxe_mr_iova_to_page_offset(mr, iova); + bytes = mr->ibmr.page_size - page_offset; if (bytes > length) bytes = length; - va = iova_to_vaddr(mr, iova, length); + index = rxe_mr_iova_to_index(mr, iova); + page = xa_load(&mr->pages, index); + if (!page) + return -2; + + va = kmap_local_page(page); if (!va) return -EFAULT; - arch_wb_cache_pmem(va, bytes); + arch_wb_cache_pmem(va + page_offset, bytes); length -= bytes; iova += bytes; - offset = 0; + page_offset = 0; } return 0; } -/* copy data from a range (vaddr, vaddr+length-1) to or from - * a mr object starting at iova. - */ +static void rxe_mr_copy_dma(struct rxe_mr *mr, u64 iova, void *addr, + unsigned int page_offset, unsigned int length, + enum rxe_mr_copy_dir dir) +{ + unsigned int bytes; + struct page *page; + u8 *va; + + while (length) { + page = virt_to_page(iova & mr->page_mask); + va = kmap_local_page(page); + bytes = min_t(unsigned int, length, PAGE_SIZE - page_offset); + + if (dir == RXE_TO_MR_OBJ) + memcpy(va + page_offset, addr, bytes); + else + memcpy(addr, va + page_offset, bytes); + + kunmap_local(va); + page_offset = 0; + iova += bytes; + addr += bytes; + length -= bytes; + } +} + int rxe_mr_copy(struct rxe_mr *mr, u64 iova, void *addr, int length, enum rxe_mr_copy_dir dir) { - int err; - int bytes; - u8 *va; - struct rxe_map **map; - struct rxe_phys_buf *buf; - int m; - int i; - size_t offset; + unsigned int page_offset; + unsigned long index; + int err; if (length == 0) return 0; if (mr->ibmr.type == IB_MR_TYPE_DMA) { - u8 *src, *dest; - - src = (dir == RXE_TO_MR_OBJ) ? addr : ((void *)(uintptr_t)iova); - - dest = (dir == RXE_TO_MR_OBJ) ? ((void *)(uintptr_t)iova) : addr; - - memcpy(dest, src, length); - + page_offset = iova & (PAGE_SIZE - 1); + rxe_mr_copy_dma(mr, iova, addr, page_offset, length, dir); return 0; } - WARN_ON_ONCE(!mr->map); - err = mr_check_range(mr, iova, length); - if (err) { - err = -EFAULT; - goto err1; - } - - lookup_iova(mr, iova, &m, &i, &offset); - - map = mr->map + m; - buf = map[0]->buf + i; - - while (length > 0) { - u8 *src, *dest; - - va = (u8 *)(uintptr_t)buf->addr + offset; - src = (dir == RXE_TO_MR_OBJ) ? addr : va; - dest = (dir == RXE_TO_MR_OBJ) ? va : addr; - - bytes = buf->size - offset; - - if (bytes > length) - bytes = length; - - memcpy(dest, src, bytes); - - length -= bytes; - addr += bytes; - - offset = 0; - buf++; - i++; - - if (i == RXE_BUF_PER_MAP) { - i = 0; - map++; - buf = map[0]->buf; - } - } - - return 0; + if (err) + return err; -err1: - return err; + page_offset = rxe_mr_iova_to_page_offset(mr, iova); + index = rxe_mr_iova_to_index(mr, iova); + return rxe_mr_copy_xarray(mr, addr, index, page_offset, length, dir); } /* copy data in or out of a wqe, i.e. sg list @@ -508,7 +439,6 @@ int copy_data( if (bytes > 0) { iova = sge->addr + offset; - err = rxe_mr_copy(mr, iova, addr, bytes, dir); if (err) goto err2; @@ -537,20 +467,47 @@ int copy_data( static DEFINE_SPINLOCK(atomic_ops_lock); +/* + * Returns: + * 0 on success + * -1 address is misaligned + * -2 access violations + */ int rxe_mr_do_atomic_op(struct rxe_mr *mr, u64 iova, int opcode, u64 compare, u64 swap_add, u64 *orig_val) { - u64 *vaddr = iova_to_vaddr(mr, iova, sizeof(u64)); + unsigned int page_offset; + struct page *page; u64 value; + u64 *va; - /* needs to match rxe_resp.c */ - if (mr->state != RXE_MR_STATE_VALID || !vaddr) - return -EFAULT; - if ((uintptr_t)vaddr & 0x7) - return -EINVAL; + if (unlikely(mr->state != RXE_MR_STATE_VALID)) + return -2; + + if (mr->ibmr.type == IB_MR_TYPE_DMA) { + page_offset = iova & (PAGE_SIZE - 1); + page = virt_to_page(iova & PAGE_MASK); + } else { + unsigned long index; + int err; + + err = mr_check_range(mr, iova, 8); + if (err) + return err; + page_offset = rxe_mr_iova_to_page_offset(mr, iova); + index = rxe_mr_iova_to_index(mr, iova); + page = xa_load(&mr->pages, index); + if (!page) + return -2; + } + + if (unlikely(page_offset & 0x7)) + return -1; + + va = kmap_local_page(page); spin_lock_bh(&atomic_ops_lock); - value = *orig_val = *vaddr; + *orig_val = value = va[page_offset >> 3]; if (opcode == IB_OPCODE_RC_COMPARE_SWAP) { if (value == compare) @@ -559,9 +516,11 @@ int rxe_mr_do_atomic_op(struct rxe_mr *mr, u64 iova, int opcode, value += swap_add; } - *vaddr = value; + va[page_offset >> 3] = value; spin_unlock_bh(&atomic_ops_lock); + kunmap_local(va); + return 0; } @@ -580,9 +539,11 @@ int rxe_mr_do_atomic_op(struct rxe_mr *mr, u64 iova, int opcode, int rxe_mr_do_atomic_write(struct rxe_mr *mr, u64 iova, void *addr) { #if defined CONFIG_64BIT - u64 *vaddr; - u64 value; + unsigned int page_offset; + struct page *page; unsigned int length = 8; + u64 value; + u64 *va; /* See IBA oA19-28 */ if (unlikely(mr->state != RXE_MR_STATE_VALID)) { @@ -590,23 +551,38 @@ int rxe_mr_do_atomic_write(struct rxe_mr *mr, u64 iova, void *addr) return -2; } + if (mr->ibmr.type == IB_MR_TYPE_DMA) { + page_offset = iova & (PAGE_SIZE - 1); + page = virt_to_page(iova & PAGE_MASK); + } else { + unsigned long index; + int err; + + /* See IBA oA19-28 */ + err = mr_check_range(mr, iova, length); + if (unlikely(err)) { + rxe_dbg_mr(mr, "iova out of range"); + return -2; + } + page_offset = rxe_mr_iova_to_page_offset(mr, iova); + index = rxe_mr_iova_to_index(mr, iova); + page = xa_load(&mr->pages, index); + if (WARN_ON(!page)) + return -2; + } + /* See IBA A19.4.2 */ - if (unlikely((uintptr_t)vaddr & 0x7 || iova & 0x7)) { + if (iova & 0x7) { rxe_dbg_mr(mr, "misaligned address"); return -1; } - vaddr = iova_to_vaddr(mr, iova, length); - if (unlikely(!vaddr)) { - rxe_dbg_mr(mr, "iova out of range"); - return -2; - } - - /* this makes no sense. What of payload is not 8? */ + va = kmap_local_page(page); memcpy(&value, addr, length); /* Do atomic write after all prior operations have completed */ - smp_store_release(vaddr, value); + smp_store_release(&va[page_offset >> 3], value); + kunmap_local(va); return 0; #else @@ -648,12 +624,6 @@ int advance_dma_data(struct rxe_dma_info *dma, unsigned int length) return 0; } -/* (1) find the mr corresponding to lkey/rkey - * depending on lookup_type - * (2) verify that the (qp) pd matches the mr pd - * (3) verify that the mr can support the requested access - * (4) verify that mr state is valid - */ struct rxe_mr *lookup_mr(struct rxe_pd *pd, int access, u32 key, enum rxe_mr_lookup_type type) { @@ -774,15 +744,8 @@ int rxe_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata) void rxe_mr_cleanup(struct rxe_pool_elem *elem) { struct rxe_mr *mr = container_of(elem, typeof(*mr), elem); - int i; rxe_put(mr_pd(mr)); ib_umem_release(mr->umem); - - if (mr->map) { - for (i = 0; i < mr->num_map; i++) - kfree(mr->map[i]); - - kfree(mr->map); - } + xa_destroy(&mr->pages); } diff --git a/drivers/infiniband/sw/rxe/rxe_resp.c b/drivers/infiniband/sw/rxe/rxe_resp.c index 1083cda22c65..b0ff36f6dc4a 100644 --- a/drivers/infiniband/sw/rxe/rxe_resp.c +++ b/drivers/infiniband/sw/rxe/rxe_resp.c @@ -744,7 +744,7 @@ static enum resp_states atomic_reply(struct rxe_qp *qp, atmeth_comp(pkt), atmeth_swap_add(pkt), &res->atomic.orig_val); - if (err == -EINVAL) + if (err == -1) return RESPST_ERR_MISALIGNED_ATOMIC; else if (err) return RESPST_ERR_RKEY_VIOLATION; diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.h b/drivers/infiniband/sw/rxe/rxe_verbs.h index bfc94caaeec5..64551cf354a6 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.h +++ b/drivers/infiniband/sw/rxe/rxe_verbs.h @@ -283,17 +283,6 @@ enum rxe_mr_lookup_type { RXE_LOOKUP_REMOTE, }; -#define RXE_BUF_PER_MAP (PAGE_SIZE / sizeof(struct rxe_phys_buf)) - -struct rxe_phys_buf { - u64 addr; - u64 size; -}; - -struct rxe_map { - struct rxe_phys_buf buf[RXE_BUF_PER_MAP]; -}; - static inline int rkey_is_mw(u32 rkey) { u32 index = rkey >> 8; @@ -311,22 +300,16 @@ struct rxe_mr { u32 rkey; enum rxe_mr_state state; int access; + atomic_t num_mw; unsigned int page_offset; unsigned int page_shift; u64 page_mask; - int map_shift; - int map_mask; u32 num_buf; u32 nbuf; - u32 max_buf; - u32 num_map; - - atomic_t num_mw; - - struct rxe_map **map; + struct xarray pages; }; static inline unsigned int mr_page_size(struct rxe_mr *mr)