From patchwork Thu Jun 25 13:08:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 215244 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=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 A2C81C433E1 for ; Thu, 25 Jun 2020 13:09:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A81B20702 for ; Thu, 25 Jun 2020 13:09:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404932AbgFYNJP (ORCPT ); Thu, 25 Jun 2020 09:09:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404922AbgFYNIz (ORCPT ); Thu, 25 Jun 2020 09:08:55 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA22EC08C5C1 for ; Thu, 25 Jun 2020 06:08:54 -0700 (PDT) Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) (envelope-from ) id 1joRca-00BrnC-JO; Thu, 25 Jun 2020 15:08:52 +0200 From: Johannes Berg To: me@bcopeland.com Cc: linux-wireless@vger.kernel.org, Johannes Berg Subject: [PATCH 1/9] wmediumd: add -lstdc++ for SANITIZE=1 Date: Thu, 25 Jun 2020 15:08:36 +0200 Message-Id: <20200625150754.5b773d0f5e50.I3d0915b84d33b5a770cef1c1273bd33ac4e72d7b@changeid> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200625130844.22893-1-johannes@sipsolutions.net> References: <20200625130844.22893-1-johannes@sipsolutions.net> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Johannes Berg It appears that in some scenarios this is necessary to get the right version of the library, otherwise some runtime linking can fail. Add -lstdc++ as required by -lasan. --- wmediumd/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wmediumd/Makefile b/wmediumd/Makefile index f75c4e8b4e3e..fa94eb01fbc2 100644 --- a/wmediumd/Makefile +++ b/wmediumd/Makefile @@ -56,7 +56,7 @@ OBJECTS += lib/uds.o lib/vhost.o lib/wallclock.o ifeq ($(SANITIZE),1) CFLAGS += -fsanitize=undefined,address # apparently these have to come first for some reason -override LDFLAGS := -lasan -lubsan $(LDFLAGS) +override LDFLAGS := -lasan -lubsan -lstdc++ $(LDFLAGS) endif all: wmediumd From patchwork Thu Jun 25 13:08:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 215245 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=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 0D69DC433E1 for ; Thu, 25 Jun 2020 13:09:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E0D9E20720 for ; Thu, 25 Jun 2020 13:09:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404971AbgFYNJM (ORCPT ); Thu, 25 Jun 2020 09:09:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404932AbgFYNIz (ORCPT ); Thu, 25 Jun 2020 09:08:55 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73E4BC08C5DB for ; Thu, 25 Jun 2020 06:08:55 -0700 (PDT) Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) (envelope-from ) id 1joRcb-00BrnC-JM; Thu, 25 Jun 2020 15:08:53 +0200 From: Johannes Berg To: me@bcopeland.com Cc: linux-wireless@vger.kernel.org, Johannes Berg Subject: [PATCH 4/9] wmediumd: init time controller connection later Date: Thu, 25 Jun 2020 15:08:39 +0200 Message-Id: <20200625150754.86118afacfc9.I314c0396c470f9368b46dc7a8758394e560f48ac@changeid> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200625130844.22893-1-johannes@sipsolutions.net> References: <20200625130844.22893-1-johannes@sipsolutions.net> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Johannes Berg Some infrastructure that starts wmediumd might wait for it to start up by checking the sockets it should offer exist, yet have time stopped during startup for debug purposes. Initialize the time connection later so that the startup can happen regardless of such a scenario. Nothing can be processed on any of the sockets until we actually get to the mainloop anyway, so this is entirely safe. --- wmediumd/wmediumd.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/wmediumd/wmediumd.c b/wmediumd/wmediumd.c index 0f45c75be9c9..d7ffd8396d8a 100644 --- a/wmediumd/wmediumd.c +++ b/wmediumd/wmediumd.c @@ -1181,18 +1181,6 @@ int main(int argc, char *argv[]) usfstl_sched_add_job(&scheduler, &ctx.intf_job); } - if (time_socket) { - usfstl_sched_ctrl_start(&ctrl, time_socket, - 1000 /* nsec per usec */, - (uint64_t)-1 /* no ID */, - &scheduler); - vusrv.scheduler = &scheduler; - vusrv.ctrl = &ctrl; - ctx.ctrl = &ctrl; - } else { - usfstl_sched_wallclock_init(&scheduler, 1000); - } - if (vusrv.socket) usfstl_vhost_user_server_start(&vusrv); @@ -1213,6 +1201,18 @@ int main(int argc, char *argv[]) if (api_socket) usfstl_uds_create(api_socket, wmediumd_api_connected, &ctx); + if (time_socket) { + usfstl_sched_ctrl_start(&ctrl, time_socket, + 1000 /* nsec per usec */, + (uint64_t)-1 /* no ID */, + &scheduler); + vusrv.scheduler = &scheduler; + vusrv.ctrl = &ctrl; + ctx.ctrl = &ctrl; + } else { + usfstl_sched_wallclock_init(&scheduler, 1000); + } + while (1) { if (time_socket) { usfstl_sched_next(&scheduler); From patchwork Thu Jun 25 13:08:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 215248 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=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 B0193C433E0 for ; Thu, 25 Jun 2020 13:08:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F93520702 for ; Thu, 25 Jun 2020 13:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404958AbgFYNI6 (ORCPT ); Thu, 25 Jun 2020 09:08:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404923AbgFYNI4 (ORCPT ); Thu, 25 Jun 2020 09:08:56 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1D6BC08C5DC for ; Thu, 25 Jun 2020 06:08:55 -0700 (PDT) Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) (envelope-from ) id 1joRcc-00BrnC-6e; Thu, 25 Jun 2020 15:08:54 +0200 From: Johannes Berg To: me@bcopeland.com Cc: linux-wireless@vger.kernel.org, Johannes Berg Subject: [PATCH 6/9] wmediumd: fix RX message with cookie Date: Thu, 25 Jun 2020 15:08:41 +0200 Message-Id: <20200625150754.f1b8860bb95b.Ifb8f79b3edacce8832697ca796861aad92b2ce7b@changeid> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200625130844.22893-1-johannes@sipsolutions.net> References: <20200625130844.22893-1-johannes@sipsolutions.net> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Johannes Berg The cookie message needs to be built properly, fix the code to do this, otherwise a client with WMEDIUMD_CTL_RX_ALL_FRAMES doesn't know its own messages. The code was just completely broken in all kinds of ways. --- wmediumd/wmediumd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/wmediumd/wmediumd.c b/wmediumd/wmediumd.c index aa169e1602be..afc4f16d9ae9 100644 --- a/wmediumd/wmediumd.c +++ b/wmediumd/wmediumd.c @@ -606,11 +606,12 @@ static void send_cloned_frame_msg(struct wmediumd *ctx, struct client *src, list_for_each_entry(client, &ctx->clients, list) { if (client->flags & WMEDIUMD_CTL_RX_ALL_FRAMES) { - if (!cmsg) { - cmsg = nlmsg_convert(nlmsg_hdr(msg)); - if (!cmsg) - continue; - nla_put_u64(msg, HWSIM_ATTR_COOKIE, cookie); + if (src == client && !cmsg) { + struct nlmsghdr *nlh = nlmsg_hdr(msg); + + cmsg = nlmsg_inherit(nlh); + nlmsg_append(cmsg, nlmsg_data(nlh), nlmsg_datalen(nlh), 0); + assert(nla_put_u64(cmsg, HWSIM_ATTR_COOKIE, cookie) == 0); } wmediumd_send_to_client(ctx, client, src == client ? cmsg : msg); From patchwork Thu Jun 25 13:08:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 215246 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=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 4BCD6C433DF for ; Thu, 25 Jun 2020 13:09:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 338A12072E for ; Thu, 25 Jun 2020 13:09:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404945AbgFYNJK (ORCPT ); Thu, 25 Jun 2020 09:09:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404944AbgFYNI4 (ORCPT ); Thu, 25 Jun 2020 09:08:56 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 424D2C08C5DD for ; Thu, 25 Jun 2020 06:08:56 -0700 (PDT) Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) (envelope-from ) id 1joRcc-00BrnC-HO; Thu, 25 Jun 2020 15:08:54 +0200 From: Johannes Berg To: me@bcopeland.com Cc: linux-wireless@vger.kernel.org, Johannes Berg Subject: [PATCH 7/9] wmediumd: add the ability to write a pcapng file Date: Thu, 25 Jun 2020 15:08:42 +0200 Message-Id: <20200625150754.554b7fc226a1.I14409b6cb5998e7bd087c1329952fbfa1a30d45e@changeid> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200625130844.22893-1-johannes@sipsolutions.net> References: <20200625130844.22893-1-johannes@sipsolutions.net> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Johannes Berg Add the ability to write a pcapng file containing all the data. The radiotap header is currently very minimal with only the frequency and the signal strength. --- wmediumd/wmediumd.c | 119 +++++++++++++++++++++++++++++++++++++++++++- wmediumd/wmediumd.h | 2 + 2 files changed, 120 insertions(+), 1 deletion(-) diff --git a/wmediumd/wmediumd.c b/wmediumd/wmediumd.c index afc4f16d9ae9..5304931fbf74 100644 --- a/wmediumd/wmediumd.c +++ b/wmediumd/wmediumd.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -309,6 +310,48 @@ static void wmediumd_notify_frame_start(struct usfstl_job *job) } } +static void log2pcap(struct wmediumd *ctx, struct frame *frame, uint64_t ts) +{ + struct { + uint8_t it_version; + uint8_t it_pad; + uint16_t it_len; + uint32_t it_present; + struct { + uint16_t freq, flags; + } channel; + uint8_t signal; + } __attribute__((packed)) radiotap_hdr = { + .it_len = htole16(sizeof(radiotap_hdr)), + .it_present = htole32(1 << 3 /* channel */ | + 1 << 5 /* signal dBm */), + .channel.freq = htole16(frame->freq), + .signal = frame->signal, + }; + struct { + uint32_t type, blocklen, ifidx, ts_hi, ts_lo, caplen, pktlen; + } __attribute__((packed)) blockhdr = { + .type = 6, + .ts_hi = ts / (1ULL << 32), + .ts_lo = ts, + .caplen = frame->data_len + sizeof(radiotap_hdr), + .pktlen = frame->data_len + sizeof(radiotap_hdr), + }; + static const uint8_t pad[3]; + uint32_t sz, align; + + sz = blockhdr.caplen + sizeof(blockhdr) + sizeof(uint32_t); + blockhdr.blocklen = (sz + 3) & ~3; + align = blockhdr.blocklen - sz; + + fwrite(&blockhdr, sizeof(blockhdr), 1, ctx->pcap_file); + fwrite(&radiotap_hdr, sizeof(radiotap_hdr), 1, ctx->pcap_file); + fwrite(frame->data, frame->data_len, 1, ctx->pcap_file); + fwrite(pad, align, 1, ctx->pcap_file); + fwrite(&blockhdr.blocklen, sizeof(blockhdr.blocklen), 1, ctx->pcap_file); + fflush(ctx->pcap_file); +} + static void queue_frame(struct wmediumd *ctx, struct station *station, struct frame *frame) { @@ -438,6 +481,29 @@ static void queue_frame(struct wmediumd *ctx, struct station *station, } } + if (ctx->pcap_file) { + log2pcap(ctx, frame, target); + + if (is_acked && !noack) { + struct { + struct frame frame; + uint16_t fc; + uint16_t dur; + uint8_t ra[6]; + } __attribute__((packed, aligned(8))) ack = { + .fc = htole16(0xd4), + .dur = htole16(ack_time_usec), + }; + + memcpy(&ack.frame, frame, sizeof(ack.frame)); + ack.frame.data_len = 10; + memcpy(ack.ra, frame->data + 10, 6); + + log2pcap(ctx, &ack.frame, + target + send_time - ack_time_usec); + } + } + target += send_time; frame->duration = send_time; @@ -1141,10 +1207,58 @@ static void print_help(int exval) printf(" -u socket expose vhost-user socket, don't use netlink\n"); printf(" -a socket expose wmediumd API socket\n"); printf(" -n force netlink use even with vhost-user\n"); + printf(" -p FILE log packets to pcapng file FILE\n"); exit(exval); } +static void init_pcapng(struct wmediumd *ctx, const char *filename) +{ + struct { + uint32_t type, blocklen, byte_order; + uint16_t ver_maj, ver_min; + uint64_t seclen; + uint32_t blocklen2; + } __attribute__((packed)) blockhdr = { + .type = 0x0A0D0D0A, + .blocklen = sizeof(blockhdr), + .byte_order = 0x1A2B3C4D, + .ver_maj = 1, + .ver_min = 0, + .seclen = -1, + .blocklen2 = sizeof(blockhdr), + }; + struct { + uint32_t type, blocklen; + uint16_t linktype, reserved; + uint32_t snaplen; + struct { + uint16_t code, len; + uint8_t val, pad[3]; + } opt_if_tsresol; + struct { + uint16_t code, len; + } opt_endofopt; + uint32_t blocklen2; + } __attribute__((packed)) idb = { + .type = 1, + .blocklen = sizeof(idb), + .linktype = 127, // radiotap + .snaplen = -1, + .opt_if_tsresol.code = 9, + .opt_if_tsresol.len = 1, + .opt_if_tsresol.val = 6, // usec + .blocklen2 = sizeof(idb), + }; + + if (!filename) + return; + + ctx->pcap_file = fopen(filename, "w+"); + fwrite(&blockhdr, sizeof(blockhdr), 1, ctx->pcap_file); + fwrite(&idb, sizeof(idb), 1, ctx->pcap_file); +} + int main(int argc, char *argv[]) { int opt; @@ -1174,7 +1288,7 @@ int main(int argc, char *argv[]) unsigned long int parse_log_lvl; char* parse_end_token; - while ((opt = getopt(argc, argv, "hVc:l:x:t:u:a:n")) != -1) { + while ((opt = getopt(argc, argv, "hVc:l:x:t:u:a:np:")) != -1) { switch (opt) { case 'h': print_help(EXIT_SUCCESS); @@ -1218,6 +1332,9 @@ int main(int argc, char *argv[]) case 'n': force_netlink = true; break; + case 'p': + init_pcapng(&ctx, optarg); + break; case '?': printf("wmediumd: Error - No such option: " "`%c'\n\n", optopt); diff --git a/wmediumd/wmediumd.h b/wmediumd/wmediumd.h index 6319bb70c8f6..8619e28cbe9a 100644 --- a/wmediumd/wmediumd.h +++ b/wmediumd/wmediumd.h @@ -227,6 +227,8 @@ struct wmediumd { u8 log_lvl; u32 need_start_notify; + + FILE *pcap_file; }; struct hwsim_tx_rate { From patchwork Thu Jun 25 13:08:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 215247 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=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, 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 A128EC433E1 for ; Thu, 25 Jun 2020 13:09:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F2FE20702 for ; Thu, 25 Jun 2020 13:09:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404964AbgFYNI7 (ORCPT ); Thu, 25 Jun 2020 09:08:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404949AbgFYNI5 (ORCPT ); Thu, 25 Jun 2020 09:08:57 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0067BC08C5C1 for ; Thu, 25 Jun 2020 06:08:56 -0700 (PDT) Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.93) (envelope-from ) id 1joRcd-00BrnC-4E; Thu, 25 Jun 2020 15:08:55 +0200 From: Johannes Berg To: me@bcopeland.com Cc: linux-wireless@vger.kernel.org, Johannes Berg Subject: [PATCH 9/9] wmediumd: lib: wallclock: fix timerfd handling Date: Thu, 25 Jun 2020 15:08:44 +0200 Message-Id: <20200625150754.61ba963a8ccf.I2aa70a3d80eba03d766b354a4ba05e8fb15e8287@changeid> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200625130844.22893-1-johannes@sipsolutions.net> References: <20200625130844.22893-1-johannes@sipsolutions.net> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Johannes Berg When we have a timerfd for wallclock integration, it is possible that the following scenario happens: * we insert an event in to the scheduler at time T * some job handling handles the event loop and the fd becomes readable and the read is handled * we go back to the scheduler, now waiting for time T, but the fd doesn't become readable because it already had This causes the scheduler to lose synchronization and nothing really works - this manifested for example when having virtual ethernet with a low latency, where the real processing time may be more than the latency. Fix this by keeping the loop entry only active when we need it, so that the fd becomes readable we don't handle it until we're in a situation where we actually want to. --- wmediumd/lib/wallclock.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/wmediumd/lib/wallclock.c b/wmediumd/lib/wallclock.c index 4f62a5894329..3fb09accba61 100644 --- a/wmediumd/lib/wallclock.c +++ b/wmediumd/lib/wallclock.c @@ -56,9 +56,13 @@ void usfstl_sched_wallclock_wait(struct usfstl_scheduler *sched) { sched->wallclock.timer_triggered = 0; + usfstl_loop_register(&sched->wallclock.entry); + while (!sched->wallclock.timer_triggered) usfstl_loop_wait_and_handle(); + usfstl_loop_unregister(&sched->wallclock.entry); + usfstl_sched_set_time(sched, sched->prev_external_sync); } @@ -76,8 +80,6 @@ void usfstl_sched_wallclock_init(struct usfstl_scheduler *sched, sched->wallclock.entry.handler = usfstl_sched_wallclock_handle_fd; sched->wallclock.nsec_per_tick = ns_per_tick; - - usfstl_loop_register(&sched->wallclock.entry); } void usfstl_sched_wallclock_exit(struct usfstl_scheduler *sched) @@ -87,8 +89,6 @@ void usfstl_sched_wallclock_exit(struct usfstl_scheduler *sched) sched->external_request = NULL; sched->external_wait = NULL; - - usfstl_loop_unregister(&sched->wallclock.entry); close(sched->wallclock.entry.fd); }