From patchwork Thu Dec 10 10:18:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 11964107 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC6CEC0018C for ; Thu, 10 Dec 2020 10:19:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DFB923AC4 for ; Thu, 10 Dec 2020 10:19:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730130AbgLJKTX (ORCPT ); Thu, 10 Dec 2020 05:19:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727278AbgLJKTL (ORCPT ); Thu, 10 Dec 2020 05:19:11 -0500 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A4D6C061793 for ; Thu, 10 Dec 2020 02:18:30 -0800 (PST) Received: by mail-ej1-x642.google.com with SMTP id g20so6575094ejb.1 for ; Thu, 10 Dec 2020 02:18:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FZj2H/4ea4ki/8QS6r4ZPiAvzyYfSVv6rdGzABwADaU=; b=A5MUOk0qIJDVs10H7gO8T+rzfFRIqSwrlemrbV8MSM/uy4EaS2I2dUlK1U0L7eFOwu 0EJzh/qw6sJq2yt3Pm9xEb0O+dJHQ5bKk8pPrcr5nYQHx5VVkQBR8CRulBD/O39hPtkF jMcUtL+S2KVo8Ar+urn4AHWseCDrzofW34PqlfVkvc19fCZmmcXOQwym5pVL/NEXtJEI f4pZlsVMCG1X2Qs50NA7V3kwUOkk5TYiZzuMZg+Ubk4940z9tgpV5r8yPFUHumcGJ0Sg jjKOtMn9OV6KmC9x9S6pf3ytCxMP+gF0dBLPKZAruS4LFT3Fl8owzB0JUvn2YfFGy7CL YaKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FZj2H/4ea4ki/8QS6r4ZPiAvzyYfSVv6rdGzABwADaU=; b=GXC2ylTeFX1lvXKlI+GkpMIoZRQCsF4vY/LvsctJ3PchbMUdVGkg+YKKo6Mf6zZmE6 CnIqzH50G0vg4R4s1wEhLoHrzLekmBoiOpDT9HIwL0+xnZZ46xDe2HZI2vTkBKTRtaYd Gau+sTDTg/uIgPi1p48mJFj9Ux3lR68g1dwYBeYnFnuRFi1RO6JNI+ENhGl1Sf4Ef99d Tmt05QVgn3b9LcJOhU4+v/dS4sSIj11oRiUWN8duPHGlVwdkzbyE8CTxXqEhOcgbMMC1 YQoWKQwUbVnZH6dgYRipr9Zl4AvOhckWQq/z1t8X8G6higG9AUGxXlHROfbrUc2OObxs QsHQ== X-Gm-Message-State: AOAM533ck40EUaCpngTC/YzGTKTYeKwgOF1v7j6MuU/KIGwyp5JIhfAp 7jU0cAkKpHScx+jOZ7MSgL2Sv8UCNZ4NQg== X-Google-Smtp-Source: ABdhPJxNg6PMre1lQA2bWVN4aZfR0DU2omI2V/L75uIA6Gacodu/kUQc2yxnanbMDRJlzCdRviQPmw== X-Received: by 2002:a17:907:2061:: with SMTP id qp1mr5542437ejb.222.1607595508790; Thu, 10 Dec 2020 02:18:28 -0800 (PST) Received: from jwang-Latitude-5491.fkb.profitbricks.net ([2001:16b8:4938:300:58f0:963a:32b2:ff05]) by smtp.gmail.com with ESMTPSA id s24sm3955878ejb.20.2020.12.10.02.18.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 02:18:28 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Md Haris Iqbal , kernel test robot Subject: [PATCHv2 for-next 1/7] block/rnbd-clt: Get rid of warning regarding size argument in strlcpy Date: Thu, 10 Dec 2020 11:18:20 +0100 Message-Id: <20201210101826.29656-2-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201210101826.29656-1-jinpu.wang@cloud.ionos.com> References: <20201210101826.29656-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Md Haris Iqbal The kernel test robot triggerred the following warning, >> drivers/block/rnbd/rnbd-clt.c:1397:42: warning: size argument in 'strlcpy' call appears to be size of the source; expected the size of the destination [-Wstrlcpy-strlcat-size] strlcpy(dev->pathname, pathname, strlen(pathname) + 1); ~~~~~~~^~~~~~~~~~~~~ To get rid of the above warning, use a kstrdup as Bart suggested. Fixes: 64e8a6ece1a5 ("block/rnbd-clt: Dynamically alloc buffer for pathname & blk_symlink_name") Reported-by: kernel test robot Signed-off-by: Md Haris Iqbal Signed-off-by: Jack Wang --- drivers/block/rnbd/rnbd-clt.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c index a199b190c73d..d63f0974bd04 100644 --- a/drivers/block/rnbd/rnbd-clt.c +++ b/drivers/block/rnbd/rnbd-clt.c @@ -1388,12 +1388,11 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess, goto out_queues; } - dev->pathname = kzalloc(strlen(pathname) + 1, GFP_KERNEL); + dev->pathname = kstrdup(pathname, GFP_KERNEL); if (!dev->pathname) { ret = -ENOMEM; goto out_queues; } - strlcpy(dev->pathname, pathname, strlen(pathname) + 1); dev->clt_device_id = ret; dev->sess = sess; From patchwork Thu Dec 10 10:18:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 11964109 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6ECABC433FE for ; Thu, 10 Dec 2020 10:19:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 38B9923AC4 for ; Thu, 10 Dec 2020 10:19:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726313AbgLJKTQ (ORCPT ); Thu, 10 Dec 2020 05:19:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728489AbgLJKTL (ORCPT ); Thu, 10 Dec 2020 05:19:11 -0500 Received: from mail-ed1-x543.google.com (mail-ed1-x543.google.com [IPv6:2a00:1450:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18D4BC061794 for ; Thu, 10 Dec 2020 02:18:31 -0800 (PST) Received: by mail-ed1-x543.google.com with SMTP id h16so4882205edt.7 for ; Thu, 10 Dec 2020 02:18:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fwUB98OMU5vN+dBpGv0EWnnHA2hhEx1MlU32S5W8EnI=; b=TiEFNbqTMOidxiiKF76b1nJcEUTnEX/1Gp682BLADV1z0pn12p2abDYLB7/eGn0RGg 7TFMN5CLsPBq6bhgi2lDmBHHLX//b1JGGTMEvq5rlk3AhdOzQUXQYo/b2gqxttuO5hN7 ctMVqjuNC8xP6FPVYug1zLMvNsPY4ZZIX98yPqTfaFtGHuSwJf5ek6KinFc7MwlrWF/c U6I3Yl4+WA2paoz5jm09WR1xm1ncRdlLvW9IS/Y9ndJO0BUes87fQ+MUiJ1t4FBSDLEp Y15XQ8/Kb5AxRgYPqiMEVjlXOrTHQ6yk1pcyiTOHSr5HE0ri+ZqxME48KuEuXWZ6GoZZ gk6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fwUB98OMU5vN+dBpGv0EWnnHA2hhEx1MlU32S5W8EnI=; b=SdPF64Xe7V/lSBK4gzoJhpXX8FM3qN2rEXTU+Gu38ppcP0pgmaLVUT7xbmPGk/eacI md6wQcHk5uGV2JbPUJIqmnC1W3b5Mx6/ok5Zw6VAJ8uQ6IHHK2dQIJkjReWwaY4TEajF FFwlDVf4bndiPIh3flm7GbQdPtpPJJR7L+gxxFADCnSK3LsXct+HcJFFHo8wlNc98Lmo xbh7BDJWsRUMonmCxagmFj8DldXqY1QUCNDmjpUzGmf808y5uNM90sAU5Erx1Zd2ZE0g s9mRc6d7YOaFIqPy4QSUiwg0A/+hqmrtPTrOONWQNDCCcDzShWeD5QyewGztnysejxz2 EM9w== X-Gm-Message-State: AOAM530dG/u5Rb/0bRVyqxr+HVLECy/Xqv/cxb4Nnum2erA68qu6gREJ tlIa0lfffEt7UOaT91gsgBHkTM4iMMghxQ== X-Google-Smtp-Source: ABdhPJyqlnZxVXoUedM40PFa8WWfqfLfB3nvMpQUl8Zxol1yqPlVY2qTy+3jKM33i3aN31NXC7OE1g== X-Received: by 2002:aa7:c84c:: with SMTP id g12mr5928364edt.193.1607595509712; Thu, 10 Dec 2020 02:18:29 -0800 (PST) Received: from jwang-Latitude-5491.fkb.profitbricks.net ([2001:16b8:4938:300:58f0:963a:32b2:ff05]) by smtp.gmail.com with ESMTPSA id s24sm3955878ejb.20.2020.12.10.02.18.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 02:18:29 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Md Haris Iqbal Subject: [PATCHv2 for-next 2/7] block/rnbd-clt: Fix possible memleak Date: Thu, 10 Dec 2020 11:18:21 +0100 Message-Id: <20201210101826.29656-3-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201210101826.29656-1-jinpu.wang@cloud.ionos.com> References: <20201210101826.29656-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org In error case, we do not free the memory for blk_symlink_name. Do it by free the memory in error case, and set to NULL afterwards. Also fix the condition in rnbd_clt_remove_dev_symlink. Fixes: 64e8a6ece1a5 ("block/rnbd-clt: Dynamically alloc buffer for pathname & blk_symlink_name") Signed-off-by: Jack Wang Reviewed-by: Md Haris Iqbal --- drivers/block/rnbd/rnbd-clt-sysfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/block/rnbd/rnbd-clt-sysfs.c b/drivers/block/rnbd/rnbd-clt-sysfs.c index a7caeedeb198..d4aa6bfc9555 100644 --- a/drivers/block/rnbd/rnbd-clt-sysfs.c +++ b/drivers/block/rnbd/rnbd-clt-sysfs.c @@ -432,7 +432,7 @@ void rnbd_clt_remove_dev_symlink(struct rnbd_clt_dev *dev) * i.e. rnbd_clt_unmap_dev_store() leading to a sysfs warning because * of sysfs link already was removed already. */ - if (strlen(dev->blk_symlink_name) && try_module_get(THIS_MODULE)) { + if (dev->blk_symlink_name && try_module_get(THIS_MODULE)) { sysfs_remove_link(rnbd_devs_kobj, dev->blk_symlink_name); kfree(dev->blk_symlink_name); module_put(THIS_MODULE); @@ -521,7 +521,8 @@ static int rnbd_clt_add_dev_symlink(struct rnbd_clt_dev *dev) return 0; out_err: - dev->blk_symlink_name[0] = '\0'; + kfree(dev->blk_symlink_name); + dev->blk_symlink_name = NULL ; return ret; } From patchwork Thu Dec 10 10:18:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 11964105 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 601CEC4361B for ; Thu, 10 Dec 2020 10:19:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 166F723AC4 for ; Thu, 10 Dec 2020 10:19:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728489AbgLJKTW (ORCPT ); Thu, 10 Dec 2020 05:19:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729565AbgLJKTM (ORCPT ); Thu, 10 Dec 2020 05:19:12 -0500 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E4EEC06179C for ; Thu, 10 Dec 2020 02:18:32 -0800 (PST) Received: by mail-ed1-x541.google.com with SMTP id r5so4875222eda.12 for ; Thu, 10 Dec 2020 02:18:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I1nkDS+t71lcZcyKCx1EdDkNSPvYcn8wLT9ZWpiLudM=; b=RPWNMP+eTWP+4JQCgK9cGj2p75kCnnScwZcNskA6nn+FE5Tj+LiOYEzLHlEPnZgk32 CRhmOvzgn09XqFTBDDRX7Ye1pb/+T0WAJp0g7w/s5Z6z6ZcsfA+MJ3325eouJjrR41vU 2svmKzmjuxSnkWeUe8GK/txAmmNHPL4g5sNLbMR6sYgfBFQLMIgBx84IA9JlMwtgMXe2 C5Wg6v2X+7sqnsr5sUFmNhmKLWocWf+GD/x/wJu/qdLpd3n9EzPxc9agLqsxoAqMWIi4 lJu9wmIg2OPu6jqU28TsE818eAchQCFRSLS5XK4GIHUXnILCjIwqHYsWfKg4P1jbVxVR LYew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I1nkDS+t71lcZcyKCx1EdDkNSPvYcn8wLT9ZWpiLudM=; b=YgZjJzf+sN9XvLDKxjIbiiO4bU7Xojhf9qfQbTJr2pK+ljrWwI6CJh8GQfXDoVYHzZ CHcX2uwhE8PnldH+TxYRtb6b1mGKO2DbaB7EpVZlVzic4g0b/XzmbZ6Sl06yHuq1ozQs Suj5OEgzkzzTa6Frl4sGuMP2ZtLRAlwOGgYX2JcnAdfSOEy2FrxwjBy0elhdEHStbMyF 5GCruxvSe9nRNdrsy0wuNJyNV64+9DvTA7gKeVS1hWYrJp3vIsZCCCsW721Js6IU6LQ/ j3aeFQpC9OnpmlJvMGiHSzTGdiEkd8Eq3OFVyyaqM4mADhkN7VSE281VwSY3+i6Gckdn RKBQ== X-Gm-Message-State: AOAM532syfCVXW29MhwWwkZ21INSMhrkHlTXYgiMgtHY9q4M/zjhZEoa z/EM7Uad9wU356mv4imfspXlSSJCVKkapQ== X-Google-Smtp-Source: ABdhPJwnQ1TRux1B6UlziLnXPzzWJZwvKYrSzLotnDqvsHV8veLu14vOvU8L2S9fQQGE2IhQqxmPaw== X-Received: by 2002:a05:6402:16c8:: with SMTP id r8mr5909508edx.59.1607595510758; Thu, 10 Dec 2020 02:18:30 -0800 (PST) Received: from jwang-Latitude-5491.fkb.profitbricks.net ([2001:16b8:4938:300:58f0:963a:32b2:ff05]) by smtp.gmail.com with ESMTPSA id s24sm3955878ejb.20.2020.12.10.02.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 02:18:30 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Md Haris Iqbal , Guoqing Jiang Subject: [PATCHv2 for-next 3/7] block/rnbd-srv: Protect dev session sysfs removal Date: Thu, 10 Dec 2020 11:18:22 +0100 Message-Id: <20201210101826.29656-4-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201210101826.29656-1-jinpu.wang@cloud.ionos.com> References: <20201210101826.29656-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Md Haris Iqbal Since the removal of the session sysfs can also be called from the function destroy_sess, there is a need to protect the call from the function rnbd_srv_sess_dev_force_close Fixes: 786998050cbc ("block/rnbd-srv: close a mapped device from server side.") Signed-off-by: Md Haris Iqbal Reviewed-by: Guoqing Jiang Signed-off-by: Jack Wang --- drivers/block/rnbd/rnbd-srv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c index d1ee72ed8384..066411cce5e2 100644 --- a/drivers/block/rnbd/rnbd-srv.c +++ b/drivers/block/rnbd/rnbd-srv.c @@ -338,9 +338,10 @@ static int rnbd_srv_link_ev(struct rtrs_srv *rtrs, void rnbd_srv_sess_dev_force_close(struct rnbd_srv_sess_dev *sess_dev) { + mutex_lock(&sess_dev->sess->lock); rnbd_srv_destroy_dev_session_sysfs(sess_dev); + mutex_unlock(&sess_dev->sess->lock); sess_dev->keep_id = true; - } static int process_msg_close(struct rtrs_srv *rtrs, From patchwork Thu Dec 10 10:18:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 11964111 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9A45C4167B for ; Thu, 10 Dec 2020 10:19:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B22723BE5 for ; Thu, 10 Dec 2020 10:19:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726363AbgLJKTa (ORCPT ); Thu, 10 Dec 2020 05:19:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725988AbgLJKTa (ORCPT ); Thu, 10 Dec 2020 05:19:30 -0500 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 202DBC0617A6 for ; Thu, 10 Dec 2020 02:18:33 -0800 (PST) Received: by mail-ed1-x542.google.com with SMTP id h16so4882327edt.7 for ; Thu, 10 Dec 2020 02:18:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1awzXDTD2OO7hinTkZTbXg+d34hetKU44PxypjgAm/U=; b=PW8i6GNTDEts8xVCi5xucWAFxFPuh2dmJbYEcpich1+UKKLdiqDckiBNu2BrG7rznM OzCpZOn03eU5AZBM3tlqmidbAAiAAuFTFsH3r/e6ofUJfZlfyMV+turURnHvhdz8iklE ZECt+NZzkjU5hhgF9CDHKOIypRrx0RlcNaDAHMRPYQGLQyh/G2kMFgnaVnphiboL+EAh ZoqVsVIKgtJ179vwwZmmySyEYU3hqttzBkzVk3lBa269DUvnPDHz0w1M8AkpL7z4jLk6 PW+FBoxe8OdPr6G19L7TWAEPJF3EwVCIL3zuA3tX1d2AvFzK3GDBSfDh0I6svngqHILJ HfMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1awzXDTD2OO7hinTkZTbXg+d34hetKU44PxypjgAm/U=; b=OPysBquLKmqWrfuEim1LBiYzN6PNAjgyiQzmWQ1pLR89qhCzg5BSI2ubVCO5Vudovk 4N3DAUxvibm3WD4Oa16cnh5ujvSNThCPodGCATtzAo9IndznJ3i1g6l7fIxDJYFXJkgr H986lPTC7LCRUE/WiqrfixQcZ5C/xYQbxe0C0CtAdkwkvw/jvVpgCQAyP5Xpo4a7NSiY zEfFcJ24Jj7sfMSNYdEOO5X45evxb4XENilVCzYidrdEXqM1jq/zHURTRaX6OpWAabMX 9TrpwbiW0i/T1E9+m/Qv5ayefXVhxzQ49Kuvcq2bm+H1rfUNKe7UTnQ+BMKALyZJu4Xl yyAA== X-Gm-Message-State: AOAM53355q+Hb6v/WOWvogDbvaKrpzKbqZHS1i4ucut5hIhDQznPR3IH jbAfuAcBqdtxRAjbr+g7rSRu62XNnMGS7Q== X-Google-Smtp-Source: ABdhPJxpJYcVSQ3/3P6wNfPRPm4yPXtyWTGh7XJkUqTl/kifz6l0UCesCSHohXtnZPimNCGimZpsLA== X-Received: by 2002:a50:fb85:: with SMTP id e5mr5899374edq.153.1607595511745; Thu, 10 Dec 2020 02:18:31 -0800 (PST) Received: from jwang-Latitude-5491.fkb.profitbricks.net ([2001:16b8:4938:300:58f0:963a:32b2:ff05]) by smtp.gmail.com with ESMTPSA id s24sm3955878ejb.20.2020.12.10.02.18.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 02:18:31 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com Subject: [PATCHv2 for-next 4/7] block/rnbd: Fix typos Date: Thu, 10 Dec 2020 11:18:23 +0100 Message-Id: <20201210101826.29656-5-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201210101826.29656-1-jinpu.wang@cloud.ionos.com> References: <20201210101826.29656-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Signed-off-by: Jack Wang --- drivers/block/rnbd/rnbd-clt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c index d63f0974bd04..3a2e6e8ed6b1 100644 --- a/drivers/block/rnbd/rnbd-clt.c +++ b/drivers/block/rnbd/rnbd-clt.c @@ -359,7 +359,7 @@ static struct rnbd_iu *rnbd_get_iu(struct rnbd_clt_session *sess, * 2nd reference is dropped after confirmation with the response is * returned. * 1st and 2nd can happen in any order, so the rnbd_iu should be - * released (rtrs_permit returned to ibbtrs) only leased after both + * released (rtrs_permit returned to rtrs) only after both * are finished. */ atomic_set(&iu->refcount, 2); @@ -803,7 +803,7 @@ static struct rnbd_clt_session *alloc_sess(const char *sessname) rnbd_init_cpu_qlists(sess->cpu_queues); /* - * That is simple percpu variable which stores cpu indeces, which are + * That is simple percpu variable which stores cpu indices, which are * incremented on each access. We need that for the sake of fairness * to wake up queues in a round-robin manner. */ @@ -1666,7 +1666,7 @@ static void rnbd_destroy_sessions(void) /* * Here at this point there is no any concurrent access to sessions * list and devices list: - * 1. New session or device can'be be created - session sysfs files + * 1. New session or device can't be created - session sysfs files * are removed. * 2. Device or session can't be removed - module reference is taken * into account in unmap device sysfs callback. From patchwork Thu Dec 10 10:18:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 11964113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C6F4C4361B for ; Thu, 10 Dec 2020 10:19:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43DBF23AC4 for ; Thu, 10 Dec 2020 10:19:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726489AbgLJKTa (ORCPT ); Thu, 10 Dec 2020 05:19:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726363AbgLJKTa (ORCPT ); Thu, 10 Dec 2020 05:19:30 -0500 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AA9BC0617A7 for ; Thu, 10 Dec 2020 02:18:34 -0800 (PST) Received: by mail-ed1-x544.google.com with SMTP id p22so4862338edu.11 for ; Thu, 10 Dec 2020 02:18:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eqN13Z7Zmi78ARogSrbtgh1onbpQXDqTjFL+v5DH/fk=; b=RWPBrFUL1XarkDV6+ii8yET+KvTsWCdagYRwdjfcHVvBlONfaZhPCyz1VWnm+axT2S ogDoHpEDQWV3RTYetpQRq/YgYqklEP7JtdZco2rR6QZ9Ch5VdaWWpeVq6KS4VN73LW48 kAvkeYkkiNJuBYizzmBTaF8ruXK9W+o8sdoB5bvD+abuHXOM+k/VOA9K6FGyD8mPnKsb C7q1SqquDCpwonhY2TkOsHXL8mtfxrVOotTikx9wDn1TJ0yRBJnbeZJjrZuEbn380emk CvjOyesb4LGQ/HNbXetRrqfz9ZBzGVu9+BVXYbHEN8khC+HBK8AAYo1y2XMTkOZ6iAZe ryNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eqN13Z7Zmi78ARogSrbtgh1onbpQXDqTjFL+v5DH/fk=; b=HBZP8mSPiSJ2Ns2Qov72yceRoNLECbMttUYTs5K97kQDSS6QXdibB2otPcQWM0kbf3 s9n8J2JWIShL7BN6eULuXDw+cs5duHkM1tex2Vb3L2rugK2+Yu/9FAajROYWBCWVTocI GTdxFHyLQoq8cjFO8r798SFE+r9XTDnTjWXmILsB2ONiNA69nA8pTcQzpkgK+hzvLTbJ tJvSvOgCQA+aQwNVM9BPnvwj4X+YxExrQh3q4bHu9e1ZeKLBMNpen5W1IFhaYAO5nH2e ZrwAIdTTvRO+L+P9AiMdmTsy+g1dMOCSXssNl15I3THXR7JD4li9X/oqdY0r6roxkt7q Pxsg== X-Gm-Message-State: AOAM532tlvq4z1KgegHdW1rt+P2rQqsg8ka2E1sa7AZH8Qak/vnJOl+n BpgpNGdZvNFBVSPTNMgimF8A9qi8zSor8w== X-Google-Smtp-Source: ABdhPJw2NJO2W0EDTxuk0SqnpJqWTF9vWhzMeOCv7imts+AB7YMbq8b9j4DmPKcGGKWJbv18IKFy9Q== X-Received: by 2002:a05:6402:1c9b:: with SMTP id cy27mr5935150edb.253.1607595512686; Thu, 10 Dec 2020 02:18:32 -0800 (PST) Received: from jwang-Latitude-5491.fkb.profitbricks.net ([2001:16b8:4938:300:58f0:963a:32b2:ff05]) by smtp.gmail.com with ESMTPSA id s24sm3955878ejb.20.2020.12.10.02.18.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 02:18:32 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Gioh Kim Subject: [PATCHv2 for-next 5/7] block/rnbd: Set write-back cache and fua same to the target device Date: Thu, 10 Dec 2020 11:18:24 +0100 Message-Id: <20201210101826.29656-6-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201210101826.29656-1-jinpu.wang@cloud.ionos.com> References: <20201210101826.29656-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Gioh Kim The rnbd-client always sets the write-back cache and fua attributes of the rnbd device queue regardless of the target device on the server. That generates IO hang issue when the target device does not support both of write-back cacne and fua. This patch adds more fields for the cache policy and fua into the device opening message. The rnbd-server sends the information if the target device supports the write-back cache and fua and rnbd-client recevives it and set the device queue accordingly. Signed-off-by: Gioh Kim [jwang: some minor change, rename a few varables, remove unrelated comments.] Signed-off-by: Jack Wang --- drivers/block/rnbd/rnbd-clt.c | 8 +++++--- drivers/block/rnbd/rnbd-clt.h | 2 ++ drivers/block/rnbd/rnbd-proto.h | 9 ++++++++- drivers/block/rnbd/rnbd-srv.c | 9 +++++++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c index 3a2e6e8ed6b1..b5fffbdeb263 100644 --- a/drivers/block/rnbd/rnbd-clt.c +++ b/drivers/block/rnbd/rnbd-clt.c @@ -88,6 +88,8 @@ static int rnbd_clt_set_dev_attr(struct rnbd_clt_dev *dev, dev->discard_alignment = le32_to_cpu(rsp->discard_alignment); dev->secure_discard = le16_to_cpu(rsp->secure_discard); dev->rotational = rsp->rotational; + dev->wc = !!(rsp->cache_policy & RNBD_WRITEBACK); + dev->fua = !!(rsp->cache_policy & RNBD_FUA); dev->max_hw_sectors = sess->max_io_size / SECTOR_SIZE; dev->max_segments = BMAX_SEGMENTS; @@ -1305,7 +1307,7 @@ static void setup_request_queue(struct rnbd_clt_dev *dev) blk_queue_max_segments(dev->queue, dev->max_segments); blk_queue_io_opt(dev->queue, dev->sess->max_io_size); blk_queue_virt_boundary(dev->queue, SZ_4K - 1); - blk_queue_write_cache(dev->queue, true, true); + blk_queue_write_cache(dev->queue, dev->wc, dev->fua); dev->queue->queuedata = dev; } @@ -1528,13 +1530,13 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname, } rnbd_clt_info(dev, - "map_device: Device mapped as %s (nsectors: %zu, logical_block_size: %d, physical_block_size: %d, max_write_same_sectors: %d, max_discard_sectors: %d, discard_granularity: %d, discard_alignment: %d, secure_discard: %d, max_segments: %d, max_hw_sectors: %d, rotational: %d)\n", + "map_device: Device mapped as %s (nsectors: %zu, logical_block_size: %d, physical_block_size: %d, max_write_same_sectors: %d, max_discard_sectors: %d, discard_granularity: %d, discard_alignment: %d, secure_discard: %d, max_segments: %d, max_hw_sectors: %d, rotational: %d, wc: %d, fua: %d)\n", dev->gd->disk_name, dev->nsectors, dev->logical_block_size, dev->physical_block_size, dev->max_write_same_sectors, dev->max_discard_sectors, dev->discard_granularity, dev->discard_alignment, dev->secure_discard, dev->max_segments, - dev->max_hw_sectors, dev->rotational); + dev->max_hw_sectors, dev->rotational, dev->wc, dev->fua); mutex_unlock(&dev->lock); diff --git a/drivers/block/rnbd/rnbd-clt.h b/drivers/block/rnbd/rnbd-clt.h index b193d5904050..efd67ae286ca 100644 --- a/drivers/block/rnbd/rnbd-clt.h +++ b/drivers/block/rnbd/rnbd-clt.h @@ -112,6 +112,8 @@ struct rnbd_clt_dev { enum rnbd_access_mode access_mode; bool read_only; bool rotational; + bool wc; + bool fua; u32 max_hw_sectors; u32 max_write_same_sectors; u32 max_discard_sectors; diff --git a/drivers/block/rnbd/rnbd-proto.h b/drivers/block/rnbd/rnbd-proto.h index ca166241452c..c1bc5c0fef71 100644 --- a/drivers/block/rnbd/rnbd-proto.h +++ b/drivers/block/rnbd/rnbd-proto.h @@ -108,6 +108,11 @@ struct rnbd_msg_close { __le32 device_id; }; +enum rnbd_cache_policy { + RNBD_FUA = 1 << 0, + RNBD_WRITEBACK = 1 << 1, +}; + /** * struct rnbd_msg_open_rsp - response message to RNBD_MSG_OPEN * @hdr: message header @@ -124,6 +129,7 @@ struct rnbd_msg_close { * @max_segments: max segments hardware support in one transfer * @secure_discard: supports secure discard * @rotation: is a rotational disc? + * @cache_policy: support write-back caching or FUA? */ struct rnbd_msg_open_rsp { struct rnbd_msg_hdr hdr; @@ -139,7 +145,8 @@ struct rnbd_msg_open_rsp { __le16 max_segments; __le16 secure_discard; u8 rotational; - u8 reserved[11]; + u8 cache_policy; + u8 reserved[10]; }; /** diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c index 066411cce5e2..b8e44331e494 100644 --- a/drivers/block/rnbd/rnbd-srv.c +++ b/drivers/block/rnbd/rnbd-srv.c @@ -550,6 +550,7 @@ static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp, struct rnbd_srv_sess_dev *sess_dev) { struct rnbd_dev *rnbd_dev = sess_dev->rnbd_dev; + struct request_queue *q = bdev_get_queue(rnbd_dev->bdev); rsp->hdr.type = cpu_to_le16(RNBD_MSG_OPEN_RSP); rsp->device_id = @@ -574,8 +575,12 @@ static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp, cpu_to_le32(rnbd_dev_get_discard_alignment(rnbd_dev)); rsp->secure_discard = cpu_to_le16(rnbd_dev_get_secure_discard(rnbd_dev)); - rsp->rotational = - !blk_queue_nonrot(bdev_get_queue(rnbd_dev->bdev)); + rsp->rotational = !blk_queue_nonrot(q); + rsp->cache_policy = 0; + if (test_bit(QUEUE_FLAG_WC, &q->queue_flags)) + rsp->cache_policy |= RNBD_WRITEBACK; + if (blk_queue_fua(q)) + rsp->cache_policy |= RNBD_FUA; } static struct rnbd_srv_sess_dev * From patchwork Thu Dec 10 10:18:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 11964115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F9DCC433FE for ; Thu, 10 Dec 2020 10:19:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 129C323B31 for ; Thu, 10 Dec 2020 10:19:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727278AbgLJKTu (ORCPT ); Thu, 10 Dec 2020 05:19:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726627AbgLJKTu (ORCPT ); Thu, 10 Dec 2020 05:19:50 -0500 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13A8EC0617B0 for ; Thu, 10 Dec 2020 02:18:35 -0800 (PST) Received: by mail-ed1-x542.google.com with SMTP id u19so4894619edx.2 for ; Thu, 10 Dec 2020 02:18:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bm9btep6i8GK5bKs9FjOPCUMFqxmQLPOMRIVlCFPe9o=; b=YlnxBXmBjWSXI9PxpvSUqrZQ/8Ld/UcuXEJuprM5xdjVPyTI7rM+YPsbI4OfwkVqoU nEiMsU352SE/lIG0Q4a64MXXnrCdLg/3PZdfjPLlJrkP5iTkal+JlVpT978uQ8YZsBzw ry48ElFloz1R4WAhz8fLfTh4qZWgO9lpeAfPNdWw7Y5ll03psrHvlwe/JBP0IAGxwHct o2sVjZ39+pmrdZL0jxF011ym+VImgFlEiwD6liG8pB6uXt9YwJG/LBcs8RqdQ/eSf+qe qWB/JqiFXyDOAEPnpD5yf404nPkm5njSE1W3FSrF+6tHehJNiZE3zwvwngpaIjBMdax+ sQ6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bm9btep6i8GK5bKs9FjOPCUMFqxmQLPOMRIVlCFPe9o=; b=UkZYjpHEs7WJx0i7W7Z+2RIYSHPcfRpP8Row3lAYS1jrtY+hF238kGCyu5AYCEDxxR sVR4/43E9X8jXvf7EHZS3PY2ugpFn9awQsWS0NfgxCXWEueQVvTvHuj+z0+cGEA57IOg aEfwBjVAFvUHgi21dQct7R52i+ZOo/4PTo0ziKm3Gulr8TUtKvqvcxbXEMCcap5gRCuJ 5Bvdv5OQYV9UEC0DMtgMRdGNepqVU3hl26QrtSlwgOgiyJODnRCKPJU3yfK1QQRKSoE7 1RkTqZnIbXBrrUmsP2k5KvNLHqRcwjB3J6YbfuHyU4WE6kLn2ao5ek+lPHzcrLYZ25nx 1R8w== X-Gm-Message-State: AOAM532xMw0ZJ4LjYeNuxYnKeJ3aZB1GQDwulQPdnv1AXBMzBdsgQdhv MDOL0iteEY58SJfUaeVzXVnBKH732xyM0g== X-Google-Smtp-Source: ABdhPJx2YPezy5skx+0OHuZBWAnSgxNuGFMOEMLkPMvt9ArAMjt6NYWcpQNFOr9BCSBHfegzTH1Hnw== X-Received: by 2002:aa7:d915:: with SMTP id a21mr5939940edr.251.1607595513623; Thu, 10 Dec 2020 02:18:33 -0800 (PST) Received: from jwang-Latitude-5491.fkb.profitbricks.net ([2001:16b8:4938:300:58f0:963a:32b2:ff05]) by smtp.gmail.com with ESMTPSA id s24sm3955878ejb.20.2020.12.10.02.18.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 02:18:33 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Gioh Kim Subject: [PATCHv2 for-next 6/7] block/rnbd-clt: Dynamically allocate sglist for rnbd_iu Date: Thu, 10 Dec 2020 11:18:25 +0100 Message-Id: <20201210101826.29656-7-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201210101826.29656-1-jinpu.wang@cloud.ionos.com> References: <20201210101826.29656-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Gioh Kim The BMAX_SEGMENT static array for scatterlist is embedded in rnbd_iu structure to avoid memory allocation in hot IO path. In many cases, we do need only several sg entries because many IOs have only several segments. This patch change rnbd_iu to check the number of segments in the request and allocate sglist dynamically. For io path, use sg_alloc_table_chained to allocate sg list faster. First it makes two sg entries after pdu of request. The sg_alloc_table_chained uses the pre-allocated sg entries if the number of segments of the request is less than two. So it reduces the number of memory allocation. Signed-off-by: Gioh Kim Signed-off-by: Jack Wang --- drivers/block/rnbd/rnbd-clt.c | 60 ++++++++++++++++++++--------------- drivers/block/rnbd/rnbd-clt.h | 10 +++++- 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c index b5fffbdeb263..5941ff7c83a8 100644 --- a/drivers/block/rnbd/rnbd-clt.c +++ b/drivers/block/rnbd/rnbd-clt.c @@ -384,6 +384,7 @@ static void rnbd_softirq_done_fn(struct request *rq) struct rnbd_iu *iu; iu = blk_mq_rq_to_pdu(rq); + sg_free_table_chained(&iu->sgt, RNBD_INLINE_SG_CNT); rnbd_put_permit(sess, iu->permit); blk_mq_end_request(rq, errno_to_blk_status(iu->errno)); } @@ -477,7 +478,7 @@ static int send_msg_close(struct rnbd_clt_dev *dev, u32 device_id, bool wait) iu->buf = NULL; iu->dev = dev; - sg_mark_end(&iu->sglist[0]); + sg_alloc_table(&iu->sgt, 1, GFP_KERNEL); msg.hdr.type = cpu_to_le16(RNBD_MSG_CLOSE); msg.device_id = cpu_to_le32(device_id); @@ -492,6 +493,7 @@ static int send_msg_close(struct rnbd_clt_dev *dev, u32 device_id, bool wait) err = errno; } + sg_free_table(&iu->sgt); rnbd_put_iu(sess, iu); return err; } @@ -564,7 +566,8 @@ static int send_msg_open(struct rnbd_clt_dev *dev, bool wait) iu->buf = rsp; iu->dev = dev; - sg_init_one(iu->sglist, rsp, sizeof(*rsp)); + sg_alloc_table(&iu->sgt, 1, GFP_KERNEL); + sg_init_one(iu->sgt.sgl, rsp, sizeof(*rsp)); msg.hdr.type = cpu_to_le16(RNBD_MSG_OPEN); msg.access_mode = dev->access_mode; @@ -572,7 +575,7 @@ static int send_msg_open(struct rnbd_clt_dev *dev, bool wait) WARN_ON(!rnbd_clt_get_dev(dev)); err = send_usr_msg(sess->rtrs, READ, iu, - &vec, sizeof(*rsp), iu->sglist, 1, + &vec, sizeof(*rsp), iu->sgt.sgl, 1, msg_open_conf, &errno, wait); if (err) { rnbd_clt_put_dev(dev); @@ -582,6 +585,7 @@ static int send_msg_open(struct rnbd_clt_dev *dev, bool wait) err = errno; } + sg_free_table(&iu->sgt); rnbd_put_iu(sess, iu); return err; } @@ -610,7 +614,8 @@ static int send_msg_sess_info(struct rnbd_clt_session *sess, bool wait) iu->buf = rsp; iu->sess = sess; - sg_init_one(iu->sglist, rsp, sizeof(*rsp)); + sg_alloc_table(&iu->sgt, 1, GFP_KERNEL); + sg_init_one(iu->sgt.sgl, rsp, sizeof(*rsp)); msg.hdr.type = cpu_to_le16(RNBD_MSG_SESS_INFO); msg.ver = RNBD_PROTO_VER_MAJOR; @@ -626,7 +631,7 @@ static int send_msg_sess_info(struct rnbd_clt_session *sess, bool wait) goto put_iu; } err = send_usr_msg(sess->rtrs, READ, iu, - &vec, sizeof(*rsp), iu->sglist, 1, + &vec, sizeof(*rsp), iu->sgt.sgl, 1, msg_sess_info_conf, &errno, wait); if (err) { rnbd_clt_put_sess(sess); @@ -636,7 +641,7 @@ static int send_msg_sess_info(struct rnbd_clt_session *sess, bool wait) } else { err = errno; } - + sg_free_table(&iu->sgt); rnbd_put_iu(sess, iu); return err; } @@ -1016,11 +1021,10 @@ static int rnbd_client_xfer_request(struct rnbd_clt_dev *dev, * See queue limits. */ if (req_op(rq) != REQ_OP_DISCARD) - sg_cnt = blk_rq_map_sg(dev->queue, rq, iu->sglist); + sg_cnt = blk_rq_map_sg(dev->queue, rq, iu->sgt.sgl); if (sg_cnt == 0) - /* Do not forget to mark the end */ - sg_mark_end(&iu->sglist[0]); + sg_mark_end(&iu->sgt.sgl[0]); msg.hdr.type = cpu_to_le16(RNBD_MSG_IO); msg.device_id = cpu_to_le32(dev->device_id); @@ -1029,13 +1033,13 @@ static int rnbd_client_xfer_request(struct rnbd_clt_dev *dev, .iov_base = &msg, .iov_len = sizeof(msg) }; - size = rnbd_clt_get_sg_size(iu->sglist, sg_cnt); + size = rnbd_clt_get_sg_size(iu->sgt.sgl, sg_cnt); req_ops = (struct rtrs_clt_req_ops) { .priv = iu, .conf_fn = msg_io_conf, }; err = rtrs_clt_request(rq_data_dir(rq), &req_ops, rtrs, permit, - &vec, 1, size, iu->sglist, sg_cnt); + &vec, 1, size, iu->sgt.sgl, sg_cnt); if (unlikely(err)) { rnbd_clt_err_rl(dev, "RTRS failed to transfer IO, err: %d\n", err); @@ -1122,6 +1126,7 @@ static blk_status_t rnbd_queue_rq(struct blk_mq_hw_ctx *hctx, struct rnbd_clt_dev *dev = rq->rq_disk->private_data; struct rnbd_iu *iu = blk_mq_rq_to_pdu(rq); int err; + blk_status_t ret = BLK_STS_IOERR; if (unlikely(dev->dev_state != DEV_STATE_MAPPED)) return BLK_STS_IOERR; @@ -1133,32 +1138,35 @@ static blk_status_t rnbd_queue_rq(struct blk_mq_hw_ctx *hctx, return BLK_STS_RESOURCE; } + iu->sgt.sgl = iu->first_sgl; + err = sg_alloc_table_chained(&iu->sgt, + /* Even-if the request has no segment, + * sglist must have one entry at least */ + blk_rq_nr_phys_segments(rq) ? : 1, + iu->sgt.sgl, + RNBD_INLINE_SG_CNT); + if (err) { + rnbd_clt_err_rl(dev, "sg_alloc_table_chained ret=%d\n", err); + rnbd_clt_dev_kick_mq_queue(dev, hctx, 10/*ms*/); + rnbd_put_permit(dev->sess, iu->permit); + return BLK_STS_RESOURCE; + } + blk_mq_start_request(rq); err = rnbd_client_xfer_request(dev, rq, iu); if (likely(err == 0)) return BLK_STS_OK; if (unlikely(err == -EAGAIN || err == -ENOMEM)) { rnbd_clt_dev_kick_mq_queue(dev, hctx, 10/*ms*/); - rnbd_put_permit(dev->sess, iu->permit); - return BLK_STS_RESOURCE; + ret = BLK_STS_RESOURCE; } - + sg_free_table_chained(&iu->sgt, RNBD_INLINE_SG_CNT); rnbd_put_permit(dev->sess, iu->permit); - return BLK_STS_IOERR; -} - -static int rnbd_init_request(struct blk_mq_tag_set *set, struct request *rq, - unsigned int hctx_idx, unsigned int numa_node) -{ - struct rnbd_iu *iu = blk_mq_rq_to_pdu(rq); - - sg_init_table(iu->sglist, BMAX_SEGMENTS); - return 0; + return ret; } static struct blk_mq_ops rnbd_mq_ops = { .queue_rq = rnbd_queue_rq, - .init_request = rnbd_init_request, .complete = rnbd_softirq_done_fn, }; @@ -1172,7 +1180,7 @@ static int setup_mq_tags(struct rnbd_clt_session *sess) tag_set->numa_node = NUMA_NO_NODE; tag_set->flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_TAG_QUEUE_SHARED; - tag_set->cmd_size = sizeof(struct rnbd_iu); + tag_set->cmd_size = sizeof(struct rnbd_iu) + RNBD_RDMA_SGL_SIZE; tag_set->nr_hw_queues = num_online_cpus(); return blk_mq_alloc_tag_set(tag_set); diff --git a/drivers/block/rnbd/rnbd-clt.h b/drivers/block/rnbd/rnbd-clt.h index efd67ae286ca..537d499dad3b 100644 --- a/drivers/block/rnbd/rnbd-clt.h +++ b/drivers/block/rnbd/rnbd-clt.h @@ -44,6 +44,13 @@ struct rnbd_iu_comp { int errno; }; +#ifdef CONFIG_ARCH_NO_SG_CHAIN +#define RNBD_INLINE_SG_CNT 0 +#else +#define RNBD_INLINE_SG_CNT 2 +#endif +#define RNBD_RDMA_SGL_SIZE (sizeof(struct scatterlist) * RNBD_INLINE_SG_CNT) + struct rnbd_iu { union { struct request *rq; /* for block io */ @@ -56,11 +63,12 @@ struct rnbd_iu { /* use to send msg associated with a sess */ struct rnbd_clt_session *sess; }; - struct scatterlist sglist[BMAX_SEGMENTS]; + struct sg_table sgt; struct work_struct work; int errno; struct rnbd_iu_comp comp; atomic_t refcount; + struct scatterlist first_sgl[]; /* must be the last one */ }; struct rnbd_cpu_qlist { From patchwork Thu Dec 10 10:18:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinpu Wang X-Patchwork-Id: 11964117 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09783C4361B for ; Thu, 10 Dec 2020 10:19:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B097123AC4 for ; Thu, 10 Dec 2020 10:19:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727647AbgLJKT4 (ORCPT ); Thu, 10 Dec 2020 05:19:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726627AbgLJKTz (ORCPT ); Thu, 10 Dec 2020 05:19:55 -0500 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14004C06138C for ; Thu, 10 Dec 2020 02:18:36 -0800 (PST) Received: by mail-ej1-x644.google.com with SMTP id lt17so6560408ejb.3 for ; Thu, 10 Dec 2020 02:18:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.ionos.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Knp0gAEhpnBnofpihCTn4KOe6yD4tuQQlDjccaInD6E=; b=BMz53dqpO38dB+5KPM6lYgaLtlBENivLclTqhYfZGPVwcAXjWpSPhLRoQDbUTiFipM KPWjtKPZZrfRi7sM7OsPRCSGJGTOwdQK2JT10p2T0ZU/dQgTq5iSInm+FHcTspf2DmZ/ 6dUWGuB6hR/b5fZro+7TDgDTMOqo2p6wPxbCxSbznP45u7k5kKkUgHwNTzq7usNQeyao S7hJG5tRdo+xIkkvu0a0Jn7t33DcJPv5o2SOFH+3LOSr7+8TwaF9vcY9HOlKtBrXfO5Z BhLtBjwnzMTkrS+ukLSR+9YMukPpYlgwDwD5q/LjobpC+dEReG9C52h+0GdmhXdpuZiI /TXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Knp0gAEhpnBnofpihCTn4KOe6yD4tuQQlDjccaInD6E=; b=SXcZrC0G/w1FWyh6Qj6ARmVtCT7nNrpk6MNwBC3wazfgZWlHkUcxejBdghibmWb3Iv qc9zjSwXBEHe5ZvNwM/9X1owv0yZwN0801z//gh1JwNI8OAmq2bDmcjP4KcQ4eIdvxZ/ LKqHWeB0IfCBDJi/fnUzB4IcVeNyt3QoomeTOB2V9HOJlpnSweC4dwlv/OdElpako0xU C9BgyFviEJ5hBRNIeEm0zu75xKdtS69osQijk1LjBqJ6mxghArppRl0nnMt90D0UZw2b /j/TVllL+XENbVEd4tw/2c4cqEHaiAR2q5zhMImNJs1QXcjPgvyZbAkHKpN6PICTofzM mkag== X-Gm-Message-State: AOAM53297vIzTX8dBo1pEpuAC2G+4l5LG2OOsv8A4Zl9YJMPW6Xv5X0a zYNtnO7Q8TD3Xv5OAfb6ifrcrS4GFy0jxA== X-Google-Smtp-Source: ABdhPJz/1eKp2m2h0bsPcUIH2SrwJy9HCOGsp3mzgR0BIGdg2xrgA9L9xcwq461gJDxI30ckwrit5w== X-Received: by 2002:a17:906:369b:: with SMTP id a27mr5909682ejc.183.1607595514616; Thu, 10 Dec 2020 02:18:34 -0800 (PST) Received: from jwang-Latitude-5491.fkb.profitbricks.net ([2001:16b8:4938:300:58f0:963a:32b2:ff05]) by smtp.gmail.com with ESMTPSA id s24sm3955878ejb.20.2020.12.10.02.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Dec 2020 02:18:34 -0800 (PST) From: Jack Wang To: linux-block@vger.kernel.org Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me, bvanassche@acm.org, danil.kipnis@cloud.ionos.com, Gioh Kim Subject: [PATCHv2 for-next 7/7] block/rnbd-clt: Does not request pdu to rtrs-clt Date: Thu, 10 Dec 2020 11:18:26 +0100 Message-Id: <20201210101826.29656-8-jinpu.wang@cloud.ionos.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201210101826.29656-1-jinpu.wang@cloud.ionos.com> References: <20201210101826.29656-1-jinpu.wang@cloud.ionos.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Gioh Kim Previously the rnbd client requested the rtrs to allocate rnbd_iu just after the rtrs_iu. So the rnbd client passes the size of rnbd_iu for rtrs_clt_open() and rtrs creates an array of rnbd_iu and rtrs_iu. For IO handling, rnbd_iu exists after the request because we pass the size of rnbd_iu when setting the tag-set. Therefore we do not use the rnbd_iu allocated by rtrs for IO handling. We only use the rnbd_iu allocated by rtrs when doing session initialization. Almost all rnbd_iu allocated by rtrs are wasted. By this patch the rnbd client does not request rnbd_iu allocation to rtrs but allocate it for itself when doing session initialization. Also remove unused rtrs_permit_to_pdu from rtrs. Signed-off-by: Gioh Kim Signed-off-by: Jack Wang --- drivers/block/rnbd/rnbd-clt.c | 17 +++++++++++++---- drivers/infiniband/ulp/rtrs/rtrs-clt.c | 6 ------ drivers/infiniband/ulp/rtrs/rtrs.h | 7 ------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c index 5941ff7c83a8..96e3f9fe8241 100644 --- a/drivers/block/rnbd/rnbd-clt.c +++ b/drivers/block/rnbd/rnbd-clt.c @@ -349,12 +349,19 @@ static struct rnbd_iu *rnbd_get_iu(struct rnbd_clt_session *sess, struct rnbd_iu *iu; struct rtrs_permit *permit; + iu = kzalloc(sizeof(*iu), GFP_KERNEL); + if (!iu) { + return NULL; + } + permit = rnbd_get_permit(sess, con_type, wait ? RTRS_PERMIT_WAIT : RTRS_PERMIT_NOWAIT); - if (unlikely(!permit)) + if (unlikely(!permit)) { + kfree(iu); return NULL; - iu = rtrs_permit_to_pdu(permit); + } + iu->permit = permit; /* * 1st reference is dropped after finishing sending a "user" message, @@ -373,8 +380,10 @@ static struct rnbd_iu *rnbd_get_iu(struct rnbd_clt_session *sess, static void rnbd_put_iu(struct rnbd_clt_session *sess, struct rnbd_iu *iu) { - if (atomic_dec_and_test(&iu->refcount)) + if (atomic_dec_and_test(&iu->refcount)) { rnbd_put_permit(sess, iu->permit); + kfree(iu); + } } static void rnbd_softirq_done_fn(struct request *rq) @@ -1218,7 +1227,7 @@ find_and_get_or_create_sess(const char *sessname, */ sess->rtrs = rtrs_clt_open(&rtrs_ops, sessname, paths, path_cnt, port_nr, - sizeof(struct rnbd_iu), + 0, /* Do not use pdu of rtrs */ RECONNECT_DELAY, BMAX_SEGMENTS, BLK_MAX_SEGMENT_SIZE, MAX_RECONNECTS); diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c index bcfa6258a7af..7644c3f627ca 100644 --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c @@ -157,12 +157,6 @@ void rtrs_clt_put_permit(struct rtrs_clt *clt, struct rtrs_permit *permit) } EXPORT_SYMBOL(rtrs_clt_put_permit); -void *rtrs_permit_to_pdu(struct rtrs_permit *permit) -{ - return permit + 1; -} -EXPORT_SYMBOL(rtrs_permit_to_pdu); - /** * rtrs_permit_to_clt_con() - returns RDMA connection pointer by the permit * @sess: client session pointer diff --git a/drivers/infiniband/ulp/rtrs/rtrs.h b/drivers/infiniband/ulp/rtrs/rtrs.h index 9af750f4d783..8738e90e715a 100644 --- a/drivers/infiniband/ulp/rtrs/rtrs.h +++ b/drivers/infiniband/ulp/rtrs/rtrs.h @@ -63,13 +63,6 @@ struct rtrs_clt *rtrs_clt_open(struct rtrs_clt_ops *ops, void rtrs_clt_close(struct rtrs_clt *sess); -/** - * rtrs_permit_to_pdu() - converts rtrs_permit to opaque pdu pointer - * @permit: RTRS permit pointer, it associates the memory allocation for future - * RDMA operation. - */ -void *rtrs_permit_to_pdu(struct rtrs_permit *permit); - enum { RTRS_PERMIT_NOWAIT = 0, RTRS_PERMIT_WAIT = 1,