From patchwork Mon Aug 16 04:05:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bongsu Jeon X-Patchwork-Id: 497901 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 E4909C4320E for ; Mon, 16 Aug 2021 04:06:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C5134619A6 for ; Mon, 16 Aug 2021 04:06:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232954AbhHPEHM (ORCPT ); Mon, 16 Aug 2021 00:07:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230257AbhHPEGs (ORCPT ); Mon, 16 Aug 2021 00:06:48 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F3EEC0613CF; Sun, 15 Aug 2021 21:06:18 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id n13-20020a17090a4e0d00b0017946980d8dso11358710pjh.5; Sun, 15 Aug 2021 21:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SRoGE6btz3FIzsoVU86GKd+sAIx4GipMBZ33HNO90os=; b=Pd9zk65/+kFF5GDGVDxQwpyZalbA3joiA6kVand7R7RU1uHhpsD7kaIuM3PCgxyhrz ooaT6q6u5i9zGkFo9PzovH1yiH3Mz0VXKar50oo/FkZanUZYZjfgWqD5qb+MdIm55O7m sSWJBHvftQ8oOjkF6g0+h6Ft0XmesX6jgxvyFYOXYkQYdav2SrMu6b1TfePXtoD53T5Y kkub9/FAtGHPp0h/6P6CA5zv1Sl+86MI4yJDpE+8TpuWfBh6V9x0KVMKA5/mhG31YYp1 v5L5FjvnOBFEPOQ3oZl1kqDT9ex0cPn0W0P3rYvCx4kws6/rASYIBZDmiUoE+B1Sl9ao gV6g== 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=SRoGE6btz3FIzsoVU86GKd+sAIx4GipMBZ33HNO90os=; b=bJkL5DrgGpZKlEKbZgSY+m8PFCvQkETfzTfw7pTFUIXHqUkKC8IwWGkwMGBpHwy48V O62oWoaWBPL06pT+a7JtuLS3ueCGm4Zrkz68T6iZg59Ggx0Q0gy7i63iBNG51P7ZHfCt voI9H+9dMwKqvN50xD74gu5DlmbA7Uk/TpWyx3ONH7YdBQYL4zLBM7SoBkkzsTtDMI/C 3MOLUS1geac0j/Zfo9qLBDhuEjlbRbBN1I9acmHLo6jRTJ3YDuovvILZemB8rWtj9WLM NUiKKabBLUcYxVQkQ6SHClqYusXFkPYRWkG8pNSeTqSyXxT/LXzfvlp22j5PUGgHoMdB zn1A== X-Gm-Message-State: AOAM530muIVpU5AV5CKKKMOtb8te9kXJr3tST9oSdhKCBCkVChjC9hZg /xEC5b6VFfwpgrTmbEdFmzA= X-Google-Smtp-Source: ABdhPJyOUpYN9GoJC+C8C2qZrzfUkPYDKbU61b/QtSTN8i0QTo860aLD7Xxl6TNxxcvcZOFhVaGZIg== X-Received: by 2002:a17:90a:35e:: with SMTP id 30mr15452139pjf.160.1629086777396; Sun, 15 Aug 2021 21:06:17 -0700 (PDT) Received: from ubuntu.localdomain ([182.226.226.37]) by smtp.gmail.com with ESMTPSA id i6sm9436998pfa.44.2021.08.15.21.06.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 21:06:16 -0700 (PDT) From: bongsu.jeon2@gmail.com To: shuah@kernel.org, krzysztof.kozlowski@canonical.com Cc: netdev@vger.kernel.org, linux-nfc@lists.01.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Bongsu Jeon Subject: [PATCH net-next 1/3] nfc: Change the virtual NCI device driver to use Wait Queue Date: Sun, 15 Aug 2021 21:05:58 -0700 Message-Id: <20210816040600.175813-2-bongsu.jeon2@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210816040600.175813-1-bongsu.jeon2@gmail.com> References: <20210816040600.175813-1-bongsu.jeon2@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Bongsu Jeon In previous version, the user level virtual device application that used this driver should have the polling scheme to read a NCI frame. To remove this polling scheme, changed the driver code to use Wait Queue. Signed-off-by: Bongsu Jeon --- drivers/nfc/virtual_ncidev.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/nfc/virtual_ncidev.c b/drivers/nfc/virtual_ncidev.c index 2ee0ec4bb739..1953904176a2 100644 --- a/drivers/nfc/virtual_ncidev.c +++ b/drivers/nfc/virtual_ncidev.c @@ -10,6 +10,7 @@ #include #include #include +#include #include enum virtual_ncidev_mode { @@ -27,6 +28,7 @@ enum virtual_ncidev_mode { NFC_PROTO_ISO15693_MASK) static enum virtual_ncidev_mode state; +static DECLARE_WAIT_QUEUE_HEAD(wq); static struct miscdevice miscdev; static struct sk_buff *send_buff; static struct nci_dev *ndev; @@ -61,6 +63,7 @@ static int virtual_nci_send(struct nci_dev *ndev, struct sk_buff *skb) } send_buff = skb_copy(skb, GFP_KERNEL); mutex_unlock(&nci_mutex); + wake_up_interruptible(&wq); return 0; } @@ -76,12 +79,11 @@ static ssize_t virtual_ncidev_read(struct file *file, char __user *buf, { size_t actual_len; - mutex_lock(&nci_mutex); - if (!send_buff) { - mutex_unlock(&nci_mutex); + wait_event_interruptible(wq, send_buff); + if (!send_buff) return 0; - } + mutex_lock(&nci_mutex); actual_len = min_t(size_t, count, send_buff->len); if (copy_to_user(buf, send_buff->data, actual_len)) { From patchwork Mon Aug 16 04:05:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bongsu Jeon X-Patchwork-Id: 497902 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=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 89F3CC4338F for ; Mon, 16 Aug 2021 04:06:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71F3B619E9 for ; Mon, 16 Aug 2021 04:06:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229669AbhHPEHH (ORCPT ); Mon, 16 Aug 2021 00:07:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232918AbhHPEHC (ORCPT ); Mon, 16 Aug 2021 00:07:02 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3E89C061764; Sun, 15 Aug 2021 21:06:23 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id qe12-20020a17090b4f8c00b00179321cbae7so14738665pjb.2; Sun, 15 Aug 2021 21:06:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4HKnHAiUNAzYRRDKiTL1R3sjGoApYCxJD2ihqVsIpwc=; b=cnlbiCfSwSvYVDsM9gSWFd5Edae4dqWRb8Mkww+8FQfkpSZUp7n7liD0gI+NkyJ98K pZ74Lr74ZEPN0EHeabD36RHeCRlpZuKW0U8Ynif6Hm/yjK8EHFGtFoKYK5r5D2VsVN3b hvyx6KUS6wWmlj86aWdOIPrkdxhAiL80ZpNKAWmejTqFyJw9etzstHgq+40LeYxaxN3G iCDARxuQK//QNj/rG2Hyi0YbyGeUuAY7dwCcsRCcgsuPeMEUxk1EBuY3otwzrdg5Tjvo QH9eMppjklUqL0b1Ngv3PuNGpUY6EGwFCza6muuDeVeqfx/V7tQ5ZVcxQ7quh3rO/nI4 zamQ== 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=4HKnHAiUNAzYRRDKiTL1R3sjGoApYCxJD2ihqVsIpwc=; b=HKJcTMKWVFZ2AWpUraQqm0CD7b0pH7NP5jwP7LkGDvZfhPkqBmWShAqXIuypgVAyGy s+IllwQPB2odCUkdhpZZvulUOScxX6tnUvmTSKEMIbrIpRrvllSj0ojC22N2gZBlBQBA b4co9tHAJSTgN/Rkn5TWkADt+3WAgMVzIhZdcQHwne4cFxERLaok9OTJLaEP6KsEC3aC Kljd4cqkYrJqZKfisWWRWdeKfqwuYuITBoToRfMeTWw3wMy98eoWTAjLWpjdhV9L2y5z uBK8SyZJQVpbe6waBFBqMsNEW+N6JZz1PYCouTp11LG2NjwIn6M+k+Sed2VyIxMhf/t3 SYJg== X-Gm-Message-State: AOAM530fA/ulWjx9d7bGRxR2OfJT4v72GZVvV8yLR37Tl8MFjfAnHsvK MRp3fQENqK6xB35HcLtQ5rU= X-Google-Smtp-Source: ABdhPJyz+/bpAfb/VTMTroBn7Rd8D8yVzz6W3NSNjnzqfouTMsyozc5eAcvRG+0S+VT6OWpxcNlAGw== X-Received: by 2002:a65:620a:: with SMTP id d10mr13996935pgv.120.1629086783287; Sun, 15 Aug 2021 21:06:23 -0700 (PDT) Received: from ubuntu.localdomain ([182.226.226.37]) by smtp.gmail.com with ESMTPSA id i6sm9436998pfa.44.2021.08.15.21.06.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Aug 2021 21:06:22 -0700 (PDT) From: bongsu.jeon2@gmail.com To: shuah@kernel.org, krzysztof.kozlowski@canonical.com Cc: netdev@vger.kernel.org, linux-nfc@lists.01.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Bongsu Jeon Subject: [PATCH net-next 2/3] selftests: Remove the polling code to read a NCI frame Date: Sun, 15 Aug 2021 21:05:59 -0700 Message-Id: <20210816040600.175813-3-bongsu.jeon2@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210816040600.175813-1-bongsu.jeon2@gmail.com> References: <20210816040600.175813-1-bongsu.jeon2@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Bongsu Jeon Because the virtual NCI device uses Wait Queue, the virtual device application doesn't need to poll the NCI frame. Signed-off-by: Bongsu Jeon Reviewed-by: Krzysztof Kozlowski --- tools/testing/selftests/nci/nci_dev.c | 33 +++++++++------------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/nci/nci_dev.c b/tools/testing/selftests/nci/nci_dev.c index 57b505cb1561..34e76c7fa1fe 100644 --- a/tools/testing/selftests/nci/nci_dev.c +++ b/tools/testing/selftests/nci/nci_dev.c @@ -270,8 +270,7 @@ static void *virtual_dev_open(void *data) dev_fd = *(int *)data; - while ((len = read(dev_fd, buf, 258)) == 0) - ; + len = read(dev_fd, buf, 258); if (len <= 0) goto error; if (len != sizeof(nci_reset_cmd)) @@ -280,8 +279,7 @@ static void *virtual_dev_open(void *data) goto error; write(dev_fd, nci_reset_rsp, sizeof(nci_reset_rsp)); - while ((len = read(dev_fd, buf, 258)) == 0) - ; + len = read(dev_fd, buf, 258); if (len <= 0) goto error; if (len != sizeof(nci_init_cmd)) @@ -290,8 +288,7 @@ static void *virtual_dev_open(void *data) goto error; write(dev_fd, nci_init_rsp, sizeof(nci_init_rsp)); - while ((len = read(dev_fd, buf, 258)) == 0) - ; + len = read(dev_fd, buf, 258); if (len <= 0) goto error; if (len != sizeof(nci_rf_disc_map_cmd)) @@ -313,8 +310,7 @@ static void *virtual_dev_open_v2(void *data) dev_fd = *(int *)data; - while ((len = read(dev_fd, buf, 258)) == 0) - ; + len = read(dev_fd, buf, 258); if (len <= 0) goto error; if (len != sizeof(nci_reset_cmd)) @@ -324,8 +320,7 @@ static void *virtual_dev_open_v2(void *data) write(dev_fd, nci_reset_rsp_v2, sizeof(nci_reset_rsp_v2)); write(dev_fd, nci_reset_ntf, sizeof(nci_reset_ntf)); - while ((len = read(dev_fd, buf, 258)) == 0) - ; + len = read(dev_fd, buf, 258); if (len <= 0) goto error; if (len != sizeof(nci_init_cmd_v2)) @@ -334,8 +329,7 @@ static void *virtual_dev_open_v2(void *data) goto error; write(dev_fd, nci_init_rsp_v2, sizeof(nci_init_rsp_v2)); - while ((len = read(dev_fd, buf, 258)) == 0) - ; + len = read(dev_fd, buf, 258); if (len <= 0) goto error; if (len != sizeof(nci_rf_disc_map_cmd)) @@ -402,8 +396,7 @@ static void *virtual_deinit(void *data) dev_fd = *(int *)data; - while ((len = read(dev_fd, buf, 258)) == 0) - ; + len = read(dev_fd, buf, 258); if (len <= 0) goto error; if (len != sizeof(nci_reset_cmd)) @@ -425,8 +418,7 @@ static void *virtual_deinit_v2(void *data) dev_fd = *(int *)data; - while ((len = read(dev_fd, buf, 258)) == 0) - ; + len = read(dev_fd, buf, 258); if (len <= 0) goto error; if (len != sizeof(nci_reset_cmd)) @@ -489,16 +481,14 @@ static void *virtual_poll_start(void *data) dev_fd = *(int *)data; - while ((len = read(dev_fd, buf, 258)) == 0) - ; + len = read(dev_fd, buf, 258); if (len <= 0) goto error; if (len != sizeof(nci_rf_discovery_cmd)) goto error; if (memcmp(nci_rf_discovery_cmd, buf, len)) goto error; - write(dev_fd, nci_rf_disc_rsp, sizeof(nci_rf_disc_rsp)) - ; + write(dev_fd, nci_rf_disc_rsp, sizeof(nci_rf_disc_rsp)); return (void *)0; error: @@ -513,8 +503,7 @@ static void *virtual_poll_stop(void *data) dev_fd = *(int *)data; - while ((len = read(dev_fd, buf, 258)) == 0) - ; + len = read(dev_fd, buf, 258); if (len <= 0) goto error; if (len != sizeof(nci_rf_deact_cmd))