From patchwork Thu Jul 26 21:57:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10546487 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A5C6C139A for ; Thu, 26 Jul 2018 21:58:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D2F02B89D for ; Thu, 26 Jul 2018 21:58:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 912162B8B2; Thu, 26 Jul 2018 21:58:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1256F2B89D for ; Thu, 26 Jul 2018 21:58:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731640AbeGZXQt (ORCPT ); Thu, 26 Jul 2018 19:16:49 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:52121 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731587AbeGZXQs (ORCPT ); Thu, 26 Jul 2018 19:16:48 -0400 Received: by mail-wm0-f66.google.com with SMTP id y2-v6so3352968wma.1 for ; Thu, 26 Jul 2018 14:58:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=HQ2KqzztHP3mx1teXSOlKaL3NSQ3ospFwrzKl4LQwXo=; b=OcrvMp3EXfeZmWkEvM5r+ccrvAR1SagRFw7L3wlgfk+c/v5m7Gg2TgZ7PJbwf3o00H qYT3XTXaTS/k2H+VqJPluvcV1fW/YMw7jDPb+RbyKjzEKikKDW9bcnJSd5WMtyKkklit s0U89ythxY3aYDZ82lhBJcmSyNiz5bv7DjWoigGdEsJKn/sy602quMFbFBGQBbwIWY3E g7+Co7C/y/kkd9SHa4wl6k02DSruZhbXoXmGZJyfGYNPuWhnOn0aoGIz1ZdZ0KyroVw/ 1+3IhnCkkn0sdzYsY+rRQ9Hr+wPjSRYFPqAJ4wBifCrJdr3azrCguiWJamfyzSEkqAwj cwMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=HQ2KqzztHP3mx1teXSOlKaL3NSQ3ospFwrzKl4LQwXo=; b=cNwJdFRyTCagRyY6v4ZIC/mVusxSfDpsK1FWgu3hIIzZaqlQTUlYA01Knh31uFwzjB Btn0iefDqMGp2xmu2MzuaO6X08r515vLE1LoVA1WM93RPrbRBJn2xbCujZlfsZa33Sb+ PNI8cZOWoYPQLGYn1H6SyYlvJovnrQBixteZ4+ObUfvu4GUvXs6FFdXoeLLZ/ztwRfkg ju19aiQK4jzbwL6sf8mtz9p/XmhDlYekuGhjn377Olutt/ke68cv/y6J4BSlvrdB1Oqx UO7bU921pcFc3RV0wDrngtoTRMM20NsxOZ0bsQoDqL0GH4q5rzi8UK6pkl78JKpqKZ6W 6oyw== X-Gm-Message-State: AOUpUlH3kuX/O8drXWNs2Yy1ilwRaGI5dm9XP2Yq6P6IJFR6a3O7WWa8 0EcTypWarqW63lRUu+52WwwvFlWEi0EKRQ== X-Google-Smtp-Source: AAOMgpcreZo93hthg7nE9AdkEOmt+yfRebRrbILJtfgK63aiHhwYEDxKxfBBcsLyNVCWltyLK/CXmA== X-Received: by 2002:a1c:ed4:: with SMTP id 203-v6mr2711780wmo.96.1532642281262; Thu, 26 Jul 2018 14:58:01 -0700 (PDT) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id z5-v6sm3411028wrv.2.2018.07.26.14.57.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 14:58:00 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.86_2) (envelope-from ) id 1fioGi-0001zx-K9; Thu, 26 Jul 2018 15:57:56 -0600 Date: Thu, 26 Jul 2018 15:57:56 -0600 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org, Leon Romanovsky , "Guy Levi(SW)" , Yishai Hadas , "Ruhl, Michael J" Subject: [PATCH v1 01/11] IB/uverbs: Remove rdma_explicit_destroy() from the ioctl methods Message-ID: <20180726215756.GA7573@ziepe.ca> References: <20180726034020.5583-1-jgg@ziepe.ca> <20180726034020.5583-2-jgg@ziepe.ca> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180726034020.5583-2-jgg@ziepe.ca> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The core code will destroy the HW object on behalf of the method, if the method provides an implementation it must simply copy data from the stub uobj into the response. Destroy methods cannot touch the HW object. Signed-off-by: Jason Gunthorpe --- drivers/infiniband/core/rdma_core.c | 5 +--- drivers/infiniband/core/uverbs_ioctl.c | 28 +++++++++++++++++-- drivers/infiniband/core/uverbs_std_types_cq.c | 21 ++++---------- 3 files changed, 32 insertions(+), 22 deletions(-) v1: - More testing found that a hunk to assign *destroy_attr was missing from uverbs_process_attr() diff --git a/drivers/infiniband/core/rdma_core.c b/drivers/infiniband/core/rdma_core.c index a63844ba841449..9e84ded6d3bee3 100644 --- a/drivers/infiniband/core/rdma_core.c +++ b/drivers/infiniband/core/rdma_core.c @@ -924,10 +924,7 @@ int uverbs_finalize_object(struct ib_uobject *uobj, rdma_lookup_put_uobject(uobj, true); break; case UVERBS_ACCESS_DESTROY: - if (commit) - ret = rdma_remove_commit_uobject(uobj); - else - rdma_lookup_put_uobject(uobj, true); + rdma_lookup_put_uobject(uobj, true); break; case UVERBS_ACCESS_NEW: if (commit) diff --git a/drivers/infiniband/core/uverbs_ioctl.c b/drivers/infiniband/core/uverbs_ioctl.c index db7a92ea5dbe87..613ed0f85900fd 100644 --- a/drivers/infiniband/core/uverbs_ioctl.c +++ b/drivers/infiniband/core/uverbs_ioctl.c @@ -51,6 +51,7 @@ static int uverbs_process_attr(struct ib_uverbs_file *ufile, u16 attr_id, const struct uverbs_attr_spec_hash *attr_spec_bucket, struct uverbs_attr_bundle_hash *attr_bundle_h, + struct uverbs_obj_attr **destroy_attr, struct ib_uverbs_attr __user *uattr_ptr) { const struct uverbs_attr_spec *spec; @@ -148,6 +149,12 @@ static int uverbs_process_attr(struct ib_uverbs_file *ufile, if (!object) return -EINVAL; + /* specs are allowed to have only one destroy attribute */ + WARN_ON(spec->u.obj.access == UVERBS_ACCESS_DESTROY && + *destroy_attr); + if (spec->u.obj.access == UVERBS_ACCESS_DESTROY) + *destroy_attr = o_attr; + /* * The type of uattr->data is u64 for UVERBS_ATTR_TYPE_IDR and * s64 for UVERBS_ATTR_TYPE_FD. We can cast the u64 to s64 @@ -235,6 +242,7 @@ static int uverbs_uattrs_process(struct ib_uverbs_file *ufile, size_t num_uattrs, const struct uverbs_method_spec *method, struct uverbs_attr_bundle *attr_bundle, + struct uverbs_obj_attr **destroy_attr, struct ib_uverbs_attr __user *uattr_ptr) { size_t i; @@ -268,7 +276,8 @@ static int uverbs_uattrs_process(struct ib_uverbs_file *ufile, attr_spec_bucket = method->attr_buckets[ret]; ret = uverbs_process_attr(ufile, uattr, attr_id, attr_spec_bucket, - &attr_bundle->hash[ret], uattr_ptr++); + &attr_bundle->hash[ret], destroy_attr, + uattr_ptr++); if (ret) { uverbs_finalize_attrs(attr_bundle, method->attr_buckets, @@ -322,9 +331,11 @@ static int uverbs_handle_method(struct ib_uverbs_attr __user *uattr_ptr, int ret; int finalize_ret; int num_given_buckets; + struct uverbs_obj_attr *destroy_attr = NULL; - num_given_buckets = uverbs_uattrs_process( - ufile, uattrs, num_uattrs, method_spec, attr_bundle, uattr_ptr); + num_given_buckets = + uverbs_uattrs_process(ufile, uattrs, num_uattrs, method_spec, + attr_bundle, &destroy_attr, uattr_ptr); if (num_given_buckets <= 0) return -EINVAL; @@ -333,7 +344,18 @@ static int uverbs_handle_method(struct ib_uverbs_attr __user *uattr_ptr, if (ret) goto cleanup; + /* + * We destroy the HW object before invoking the handler, handlers do + * not get to manipulate the HW objects. + */ + if (destroy_attr) { + ret = rdma_explicit_destroy(destroy_attr->uobject); + if (ret) + goto cleanup; + } + ret = method_spec->handler(ibdev, ufile, attr_bundle); + cleanup: finalize_ret = uverbs_finalize_attrs(attr_bundle, method_spec->attr_buckets, diff --git a/drivers/infiniband/core/uverbs_std_types_cq.c b/drivers/infiniband/core/uverbs_std_types_cq.c index c71305fc043332..32930880975e56 100644 --- a/drivers/infiniband/core/uverbs_std_types_cq.c +++ b/drivers/infiniband/core/uverbs_std_types_cq.c @@ -176,21 +176,12 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_DESTROY)(struct ib_device *ib_dev, { struct ib_uobject *uobj = uverbs_attr_get_uobject(attrs, UVERBS_ATTR_DESTROY_CQ_HANDLE); - struct ib_uverbs_destroy_cq_resp resp; - struct ib_ucq_object *obj; - int ret; - - if (IS_ERR(uobj)) - return PTR_ERR(uobj); - - obj = container_of(uobj, struct ib_ucq_object, uobject); - - ret = rdma_explicit_destroy(uobj); - if (ret) - return ret; - - resp.comp_events_reported = obj->comp_events_reported; - resp.async_events_reported = obj->async_events_reported; + struct ib_ucq_object *obj = + container_of(uobj, struct ib_ucq_object, uobject); + struct ib_uverbs_destroy_cq_resp resp = { + .comp_events_reported = obj->comp_events_reported, + .async_events_reported = obj->async_events_reported + }; return uverbs_copy_to(attrs, UVERBS_ATTR_DESTROY_CQ_RESP, &resp, sizeof(resp));