From patchwork Thu Oct 31 13:26:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eli Cohen X-Patchwork-Id: 3120511 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9967BBF924 for ; Thu, 31 Oct 2013 13:27:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F329120453 for ; Thu, 31 Oct 2013 13:26:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C4908203E6 for ; Thu, 31 Oct 2013 13:26:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754188Ab3JaN05 (ORCPT ); Thu, 31 Oct 2013 09:26:57 -0400 Received: from mail-ee0-f42.google.com ([74.125.83.42]:65065 "EHLO mail-ee0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753203Ab3JaN04 (ORCPT ); Thu, 31 Oct 2013 09:26:56 -0400 Received: by mail-ee0-f42.google.com with SMTP id b45so1696041eek.29 for ; Thu, 31 Oct 2013 06:26:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oJfFluze5puIND7xWHcXE54ey9LQbkBLtV7B4y9Scmc=; b=bfK41voe0ikkGssqDjEc+4gpmkF3C/sCBbH34IomwC6o8l2LA5m3QeftYBIkf1Pnmi lH2Nm3qZAlFTnd6QLOeeL/X8Bf1+HXJU0044tVjnWAI0Bdi3A7QGKdUj5D88Bo2JGv1N mTzFBVZAXzPfacaNHRJEZV9tCKx6Q15Vc3OLZ0PoH2Eulk2uEX9hF0jaT6qKZsWJRM/a dtd0QHOOfONoXIOpsMC4wck9BBR8oY6FyQHzdAeWgI2YdlBv3XHfRkgdNX8BwoTx3vni nhBIQMMnccu7XMKCAwQAHt5pptQTbgwJP5nVko+Hs284QayTgpUEDSRlp/u08Ux2ftx7 xfIg== X-Gm-Message-State: ALoCoQmoit0FEmwWBfIVL+yH8IyXtjcGhUqvFL+kZYIoOih11P0o7cgdomMo7cAcRbaBKqmpN9rh X-Received: by 10.14.104.5 with SMTP id h5mr3288832eeg.58.1383226015549; Thu, 31 Oct 2013 06:26:55 -0700 (PDT) Received: from localhost (out.voltaire.com. [193.47.165.251]) by mx.google.com with ESMTPSA id a1sm8632871eem.1.2013.10.31.06.26.54 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 31 Oct 2013 06:26:55 -0700 (PDT) From: Eli Cohen To: roland@kernel.org Cc: linux-rdma@vger.kernel.org, amirv@mellanox.com, ogerlitz@mellanox.com, yevgenyp@mellanox.com, Eli Cohen Subject: [PATCH for-next 2/6] IB/core: Encorce MR access rights rules on kernel consumers Date: Thu, 31 Oct 2013 15:26:32 +0200 Message-Id: <1383225996-14828-3-git-send-email-eli@mellanox.com> X-Mailer: git-send-email 1.8.4.1 In-Reply-To: <1383225996-14828-1-git-send-email-eli@mellanox.com> References: <1383225996-14828-1-git-send-email-eli@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Enforce the rule that when requesting remote write or atomic permissions, local write must be indicated as well. See IB spec 11.2.8.2. Spotted by: Hagay Abramovsky Signed-off-by: Eli Cohen --- drivers/infiniband/core/uverbs_cmd.c | 10 +++------- drivers/infiniband/core/verbs.c | 14 ++++++++++++++ include/rdma/ib_verbs.h | 13 +++++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index 5bb2a82d..7f671b7 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -939,13 +939,9 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file, if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK)) return -EINVAL; - /* - * Local write permission is required if remote write or - * remote atomic permission is also requested. - */ - if (cmd.access_flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) && - !(cmd.access_flags & IB_ACCESS_LOCAL_WRITE)) - return -EINVAL; + ret = ib_check_mr_access(cmd.access_flags); + if (ret) + return ret; uobj = kmalloc(sizeof *uobj, GFP_KERNEL); if (!uobj) diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index a321df2..b7f21d7 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -958,6 +958,11 @@ EXPORT_SYMBOL(ib_resize_cq); struct ib_mr *ib_get_dma_mr(struct ib_pd *pd, int mr_access_flags) { struct ib_mr *mr; + int err; + + err = ib_check_mr_access(mr_access_flags); + if (err) + return ERR_PTR(err); mr = pd->device->get_dma_mr(pd, mr_access_flags); @@ -980,6 +985,11 @@ struct ib_mr *ib_reg_phys_mr(struct ib_pd *pd, u64 *iova_start) { struct ib_mr *mr; + int err; + + err = ib_check_mr_access(mr_access_flags); + if (err) + return ERR_PTR(err); if (!pd->device->reg_phys_mr) return ERR_PTR(-ENOSYS); @@ -1010,6 +1020,10 @@ int ib_rereg_phys_mr(struct ib_mr *mr, struct ib_pd *old_pd; int ret; + ret = ib_check_mr_access(mr_access_flags); + if (ret) + return ret; + if (!mr->device->rereg_phys_mr) return -ENOSYS; diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index e393171..8f462a6 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -2384,4 +2384,17 @@ struct ib_flow *ib_create_flow(struct ib_qp *qp, struct ib_flow_attr *flow_attr, int domain); int ib_destroy_flow(struct ib_flow *flow_id); +static inline int ib_check_mr_access(int flags) +{ + /* + * Local write permission is required if remote write or + * remote atomic permission is also requested. + */ + if (flags & (IB_ACCESS_REMOTE_ATOMIC | IB_ACCESS_REMOTE_WRITE) && + !(flags & IB_ACCESS_LOCAL_WRITE)) + return -EINVAL; + + return 0; +} + #endif /* IB_VERBS_H */