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 838DFC433F5 for ; Thu, 5 May 2022 13:38:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=iNCWFKzm430XXHX9xLlEge2B08P/sszyAC5WbnoeHJU=; b=nEgve0SLwxZvSgkWkrGj0DsvBG SojTb6w3kn4iXuXznLaxuOptlHxvh1lfzV6hhDaqnI3bj/jkfNfpv3NEZVkCG9HKdUAFpoXRJd0Jm tOTNplV+6tXcd+ZR9VmgptNnsoBcL2HE7ysz5p0QKhg7iZ3sQ2eVZIxfdPL4E9RvQfRJv/vJRFDl4 wk9XKar7Wo03lkusjZjTsIe+7Ok+LaULLweOABHGJca070AGAlRHeTuNSdlxOfgNshRJC16Zs1hQ0 nWjOzdVSsKr8mqXLWLFcZEmZBhJzTrFCHpojIcnhZh0ZS56JiHaLYY4Lybgm1F3LJhwoxhXZ2daTD bRHQjvAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nmbgn-00G57K-OS; Thu, 05 May 2022 13:38:41 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nmbgl-00G55Y-23 for linux-nvme@lists.infradead.org; Thu, 05 May 2022 13:38:40 +0000 Received: by mail-pj1-x1034.google.com with SMTP id qe3-20020a17090b4f8300b001dc24e4da73so5670167pjb.1 for ; Thu, 05 May 2022 06:38:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=iNCWFKzm430XXHX9xLlEge2B08P/sszyAC5WbnoeHJU=; b=KXTrYJvc/6dhACmv+XHv1BYrkg4M2puEeZahBJUNUn/xXrFCKWsTns9UST1o3e3b76 hiLDUeZM5TjU8YJLGd/YIPnXikXALp3bG9IVa9tG0EzBNzbhpbccLGvAlO61y4FfuBLz tO0Ct50bJSHST5G90CvXZC4kQVukNlej5dZPE9kX8Ob2vnPdATfKaGchPS/L4YQ35bI4 elMHSlLJZu8o7uL/Bb8Py+TXSuUIoyjWZvfG/URE0eNaOpHyfjkL3DE9wl8IKLpV4ebJ tjD/m/V73CBSFNVGDVIvcsUhTlqRlPMmefwODFXQEo+e9pChskU8ECpp8JzIkI1p7CEs I/0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=iNCWFKzm430XXHX9xLlEge2B08P/sszyAC5WbnoeHJU=; b=PXetKivHBAD1BYBL5Jx+Av7mnKIeGp5FXp0Z2Hf/OD4DXISP2pFCaSONrwDsuAXueM RjnWh/aIO4804w5xWc3McVsjgdTqPyVHDsn44Hfr6VDxb8x0EB1RF3BRbvWQyGOVWRE0 TjbOcgfZ8x11f0lZU+EtnP4kRrwqnhxIsICTsLGbn9ZcscMVEXTatu7yItrJXtJT1qQ5 gUM6tcXX01lfUiRU0wXq3X3YIPN8DdukTuJxbP5xyT50Nhjlw6d3nz9Gbbangbeivewb j9pLcvvGM1+mPP9TXEefBnRDTy7jTFpbzD50TNri7PUGWPeHuFulw3nCWYfRl5Te6mFq hUHg== X-Gm-Message-State: AOAM533lGoPx4qvWKA/Upx49X6WleStp2m8JWOllhfzDj34McNFn/FJf dlUFB3r+W/zlJO7zKjBZcoMDDw== X-Google-Smtp-Source: ABdhPJwjFQeh1yi+86NAb1iw1sGLkFH+B5HRlCYzxg07JVOyiJ2DwgDCqJQuGFEYjIelOEkJCmspTA== X-Received: by 2002:a17:90a:5b09:b0:1cd:b3d3:a3f3 with SMTP id o9-20020a17090a5b0900b001cdb3d3a3f3mr6328234pji.9.1651757913585; Thu, 05 May 2022 06:38:33 -0700 (PDT) Received: from [192.168.4.166] (cpe-72-132-29-68.dc.res.rr.com. [72.132.29.68]) by smtp.gmail.com with ESMTPSA id a10-20020a170902b58a00b0015e9f45c1f4sm1511480pls.186.2022.05.05.06.38.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 05 May 2022 06:38:33 -0700 (PDT) Message-ID: Date: Thu, 5 May 2022 07:38:31 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH v4 4/5] nvme: wire-up uring-cmd support for io-passthru on char-device. Content-Language: en-US To: Kanchan Joshi , hch@lst.de Cc: io-uring@vger.kernel.org, linux-nvme@lists.infradead.org, asml.silence@gmail.com, ming.lei@redhat.com, mcgrof@kernel.org, shr@fb.com, joshiiitr@gmail.com, anuj20.g@samsung.com, gost.dev@samsung.com References: <20220505060616.803816-1-joshi.k@samsung.com> <20220505060616.803816-5-joshi.k@samsung.com> From: Jens Axboe In-Reply-To: <20220505060616.803816-5-joshi.k@samsung.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220505_063839_153702_8AC0A844 X-CRM114-Status: GOOD ( 14.77 ) X-BeenThere: linux-nvme@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-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org On 5/5/22 12:06 AM, Kanchan Joshi wrote: > +static int nvme_uring_cmd_io(struct nvme_ctrl *ctrl, struct nvme_ns *ns, > + struct io_uring_cmd *ioucmd, unsigned int issue_flags) > +{ > + struct nvme_uring_cmd *cmd = > + (struct nvme_uring_cmd *)ioucmd->cmd; > + struct request_queue *q = ns ? ns->queue : ctrl->admin_q; > + struct nvme_command c; > + struct request *req; > + unsigned int rq_flags = 0; > + blk_mq_req_flags_t blk_flags = 0; > + > + if (!capable(CAP_SYS_ADMIN)) > + return -EACCES; > + if (cmd->flags) > + return -EINVAL; > + if (!nvme_validate_passthru_nsid(ctrl, ns, cmd->nsid)) > + return -EINVAL; > + > + if (issue_flags & IO_URING_F_NONBLOCK) { > + rq_flags = REQ_NOWAIT; > + blk_flags = BLK_MQ_REQ_NOWAIT; > + } > + memset(&c, 0, sizeof(c)); > + c.common.opcode = cmd->opcode; > + c.common.flags = cmd->flags; > + c.common.nsid = cpu_to_le32(cmd->nsid); > + c.common.cdw2[0] = cpu_to_le32(cmd->cdw2); > + c.common.cdw2[1] = cpu_to_le32(cmd->cdw3); > + c.common.cdw10 = cpu_to_le32(cmd->cdw10); > + c.common.cdw11 = cpu_to_le32(cmd->cdw11); > + c.common.cdw12 = cpu_to_le32(cmd->cdw12); > + c.common.cdw13 = cpu_to_le32(cmd->cdw13); > + c.common.cdw14 = cpu_to_le32(cmd->cdw14); > + c.common.cdw15 = cpu_to_le32(cmd->cdw15); > + > + req = nvme_alloc_user_request(q, &c, nvme_to_user_ptr(cmd->addr), > + cmd->data_len, nvme_to_user_ptr(cmd->metadata), > + cmd->metadata_len, 0, cmd->timeout_ms ? > + msecs_to_jiffies(cmd->timeout_ms) : 0, 0, rq_flags, > + blk_flags); You need to be careful with reading/re-reading the shared memory. For example, you do: if (!nvme_validate_passthru_nsid(ctrl, ns, cmd->nsid)) return -EINVAL; but then later read it again: c.common.nsid = cpu_to_le32(cmd->nsid); What happens if this changes in between the validation and assigning it here? Either this needs to be a single read and validation, or the validation doesn't really matter. I'd make this: c.common.opcode = READ_ONCE(cmd->opcode); c.common.flags = READ_ONCE(cmd->flags); c.common.nsid = cpu_to_le32(READ_ONCE(cmd->nsid)); if (!nvme_validate_passthru_nsid(ctrl, ns, le32_to_cpu(c.common.nsid))); return -EINVAL; c.common.cdw2[0] = cpu_to_le32(READ_ONCE(cmd->cdw2)); c.common.cdw2[1] = cpu_to_le32(READ_ONCE(cmd->cdw3)); c.common.metadata = 0; memset(&c.common.dptr, 0, sizeof(c.common.dptr)); c.common.cdw10 = cpu_to_le32(READ_ONCE(cmd->cdw10)); c.common.cdw11 = cpu_to_le32(READ_ONCE(cmd->cdw11)); c.common.cdw12 = cpu_to_le32(READ_ONCE(cmd->cdw12)); c.common.cdw13 = cpu_to_le32(READ_ONCE(cmd->cdw13)); c.common.cdw14 = cpu_to_le32(READ_ONCE(cmd->cdw14)); c.common.cdw15 = cpu_to_le32(READ_ONCE(cmd->cdw15)); and then consider the ones passed in to nvme_alloc_user_request() as well. -- Jens Axboe