From patchwork Sat Mar 26 02:43:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng He X-Patchwork-Id: 1609637 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=PX5l/gzK; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KQNYk4Nlhz9sG1 for ; Sat, 26 Mar 2022 13:43:22 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 451E6402F2; Sat, 26 Mar 2022 02:43:19 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QgSuMd85Fdvw; Sat, 26 Mar 2022 02:43:18 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 9297540002; Sat, 26 Mar 2022 02:43:13 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6E83CC002C; Sat, 26 Mar 2022 02:43:13 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 14B88C0012 for ; Sat, 26 Mar 2022 02:43:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 0254E40103 for ; Sat, 26 Mar 2022 02:43:12 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MouWydEZ-OVb for ; Sat, 26 Mar 2022 02:43:11 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by smtp2.osuosl.org (Postfix) with ESMTPS id 4B75440002 for ; Sat, 26 Mar 2022 02:43:11 +0000 (UTC) Received: by mail-pj1-x1031.google.com with SMTP id mj15-20020a17090b368f00b001c637aa358eso13898278pjb.0 for ; Fri, 25 Mar 2022 19:43:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JqNGiUGP6TiAl5zgYtWVdUDDi8Gyn7oy6EN4CQPMmW0=; b=PX5l/gzKVtaIB9rLJ7ZZ82OwukN0pLL0viHl4DLcrviCA5MY+j04/Fp2qdAiLsFZRQ zUARizPiXVYPlQZUndkSPvqIQhkIHKrpzO9fno3NaFvd8c1bqkwiy8zZpjJU3NJxyVgv 60JXGlmukNxRnrev20INjA9EpsXfCGDmi2jBB6C/iyMyTlir6T3lp/SwI4CjOwiOvPdh bBrCk27G4j5PWzGuJFa4Jmf14XBGmCfBdqzM+U4yJdi4fzP/tiT1YbECkZxOuQsbG4Y6 PD0PjmuPTW5KLoguCleuFdqlgKzpXKELYtAcundZQBD8imkNfxKi465a6N2P4w0QbiTo jpHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JqNGiUGP6TiAl5zgYtWVdUDDi8Gyn7oy6EN4CQPMmW0=; b=6rton7vyv223790GhWG/59rjBspCFa/Vv1VGaHVPqe5y57IMRUu/vUW/WQOkwGREJZ 5enWslgFZ+gehj79f3dqUX53dkxHazFIg7vROslkVEjdh1o2yVrM66LQFftwB2I4+Yls xCEodQ96jORI6J+39xaP9CJJeUcvhFnJT1w7LTU4cZB04K73dZEg2orfHiKcr3FzIuEF gInmgR4Q6j/gGyHFiob2wVOy9VISe0zs65zT0r5BkzxGPs1Q/NI1KlcB4+/FTanvLa6k ml3tfk0oNJPIA1ChMsTgAoFRPigUVzl/2shjSQMQp8IUWmqimaNwEcXVFhUq9VvMgbhU V86g== X-Gm-Message-State: AOAM533ZWgENiYQWq3RouveHMXm7GMwI0oV/Mgl2cGsjiNWi1rhBtnee b1NYgiruRc2KiXvFK5uSGrMN3k3CwpBCbg== X-Google-Smtp-Source: ABdhPJw/bn/tJNqGEQGK9BcpyjovTkfEBvhPOYBIUE4SLNlLffWozab1APKcZsf6Cq+GZZCBthfGcw== X-Received: by 2002:a17:902:8b87:b0:14d:7920:e54a with SMTP id ay7-20020a1709028b8700b0014d7920e54amr14670924plb.140.1648262590419; Fri, 25 Mar 2022 19:43:10 -0700 (PDT) Received: from localhost ([139.177.225.252]) by smtp.gmail.com with ESMTPSA id m4-20020a17090a7f8400b001bef3fc3938sm7081808pjl.49.2022.03.25.19.43.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 19:43:09 -0700 (PDT) From: Peng He X-Google-Original-From: Peng He To: dev@openvswitch.org Date: Sat, 26 Mar 2022 02:43:05 +0000 Message-Id: <20220326024306.27661-1-hepeng.0320@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307222754.2396907-1-i.maximets@ovn.org> References: <20220307222754.2396907-1-i.maximets@ovn.org> MIME-Version: 1.0 Cc: david.marchand@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [ovs-dev v1 1/2] ovs-rcu: add rcu_barrier X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" rcu_barrier will block the current thread until all the postponed rcu job has been finished. it's like the OVS's version of the kernel rcu_barrier() Signed-off-by: Peng He --- lib/ovs-rcu.c | 31 +++++++++++++++++++++++++++++++ lib/ovs-rcu.h | 4 ++++ 2 files changed, 35 insertions(+) diff --git a/lib/ovs-rcu.c b/lib/ovs-rcu.c index 1866bd308..2bf6b6eae 100644 --- a/lib/ovs-rcu.c +++ b/lib/ovs-rcu.c @@ -444,3 +444,34 @@ ovsrcu_init_module(void) ovsthread_once_done(&once); } } + +static void +ovsrcu_barrier_func(void *seq_) +{ + struct seq *seq = (struct seq*)seq_; + seq_change(seq); +} + +bool +ovsrcu_barrier(struct seq *seq, long long int timeout) +{ + /* first let all threads flush their cbset */ + ovsrcu_synchronize(); + + /* then register a new cbset, ensure this cbset + * is at the tail of global listi + */ + uint64_t seqno = seq_read(seq); + ovsrcu_postpone__(ovsrcu_barrier_func, (void*)seq); + long long int now = time_msec(); + long long int deadline = now + timeout; + + do { + seq_wait(seq, seqno); + poll_timer_wait_until(deadline); + poll_block(); + now = time_msec(); /* update now */ + } while (seqno == seq_read(seq) && now < deadline); + + return !(seqno == seq_read(seq)); +} diff --git a/lib/ovs-rcu.h b/lib/ovs-rcu.h index ecc4c9201..c9c044e06 100644 --- a/lib/ovs-rcu.h +++ b/lib/ovs-rcu.h @@ -159,6 +159,7 @@ #include "compiler.h" #include "ovs-atomic.h" +#include "seq.h" #if __GNUC__ #define OVSRCU_TYPE(TYPE) struct { ATOMIC(TYPE) p; } @@ -310,4 +311,7 @@ void ovsrcu_synchronize(void); void ovsrcu_exit(void); +bool ovsrcu_barrier(struct seq *seq, long long int timeout); + + #endif /* ovs-rcu.h */ From patchwork Sat Mar 26 02:43:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng He X-Patchwork-Id: 1609638 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=M83SGJWH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KQNYm64RKz9sG1 for ; Sat, 26 Mar 2022 13:43:24 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 9989E408C6; Sat, 26 Mar 2022 02:43:21 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WACGNcErQHA0; Sat, 26 Mar 2022 02:43:20 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id DF4C040324; Sat, 26 Mar 2022 02:43:19 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 52E71C002C; Sat, 26 Mar 2022 02:43:19 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id AF543C0012 for ; Sat, 26 Mar 2022 02:43:18 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 9F2D9841C9 for ; Sat, 26 Mar 2022 02:43:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cZdjB46ll5di for ; Sat, 26 Mar 2022 02:43:18 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by smtp1.osuosl.org (Postfix) with ESMTPS id 2C4258417D for ; Sat, 26 Mar 2022 02:43:14 +0000 (UTC) Received: by mail-pl1-x62a.google.com with SMTP id k6so10050370plg.12 for ; Fri, 25 Mar 2022 19:43:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FdnsHBGRU1X/IcepnYFSbg7O2Ee+8OU6r/pwBVGV9YI=; b=M83SGJWHDo4Mm4DDEVfbmnmNuWmYmEni9uhQvfvPb9UFEc+MPwz+ahh8T4VG/kDQz3 aAo+rW6FVUrcp48bf5QtEq44Qh/3DoCbS3a3/20Dtk8lnNqDOVbwz9TGJwEH65xh0NaX qNvKoNXjp2qBw9rdq+TeDTBKUyHNCv1FC+S1xpuPzaM+cKgiXcnfu9FzLUcdAI1SmAMu okjEPQouixNrEqe9i9drHh1LOayQ3MJZsEJda/jDDobFMIYkVlrfqrpZlIaxVi9pCjwY /NKoLDzIgydMqYfL0p5CoRNl0DqpzbUW61oCqp+zymZbEgYb/wtENQrV+Vvtkan5EPv3 HT6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FdnsHBGRU1X/IcepnYFSbg7O2Ee+8OU6r/pwBVGV9YI=; b=vCNW7V+dck+j9smTKRUmHo1b7KKNtgPj7jX2B12bDPch42Ka/4D+uUzd4fFj9cu5sX 6MtOzCyF0AFhhqaVD/0j5tyHg5VsziIYXTFT//IO8uUZcmCilyhw2nSXgDDJ1tPNEqRf 2nZGlyUi4ofGeg/wViRIh84rkmifTB/ROacdT/lyffdQ/b1C1kW29cnUFeRQu06xB4Kw apqkEj5gmaSlhKcxkCf9iXXCwDEv/wpFgRMYbEa5BWUb2Q6mRumQr/TwB6H2XR7S72eV eg/n2z4pEXsHCTg+0C5F5XZMw7IsAgfxHl60xb/9bvac50iK7CgTz+CgU0uE5nin4RuF 5Wrg== X-Gm-Message-State: AOAM532HpZuNLHuu4v0pqalcDKwPg2wQp2QMr3tP8Qr/kKLAnpNpo2ji x+qmPKkAWfkyzjuocqE18GrjpyRIGZdIIQ== X-Google-Smtp-Source: ABdhPJwO9QUIAjDtyNbe11efJDblTa2jrtLM92dIALTjqq/nL7GMRML0q9ebH5AHQONnGYbISxpzww== X-Received: by 2002:a17:90b:1b03:b0:1c7:778b:d4ce with SMTP id nu3-20020a17090b1b0300b001c7778bd4cemr23654707pjb.128.1648262593519; Fri, 25 Mar 2022 19:43:13 -0700 (PDT) Received: from localhost ([139.177.225.252]) by smtp.gmail.com with ESMTPSA id y41-20020a056a001ca900b004fb000ccd92sm4724401pfw.96.2022.03.25.19.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 19:43:13 -0700 (PDT) From: Peng He X-Google-Original-From: Peng He To: dev@openvswitch.org Date: Sat, 26 Mar 2022 02:43:06 +0000 Message-Id: <20220326024306.27661-2-hepeng.0320@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220326024306.27661-1-hepeng.0320@bytedance.com> References: <20220307222754.2396907-1-i.maximets@ovn.org> <20220326024306.27661-1-hepeng.0320@bytedance.com> MIME-Version: 1.0 Cc: david.marchand@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [ovs-dev v1 2/2] ofproto-dpif: fix meter use-after-free X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" add a rcu_barrier before close_dpif_backer to ensure that all meters has been freed before id_pool_destory meter's id-pool. Signed-off-by: Peng He --- ofproto/ofproto-dpif.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index a4c44052d..1739544e5 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -1797,6 +1797,16 @@ add_internal_flows(struct ofproto_dpif *ofproto) return error; } +static void +ofproto_rcu_barrier(void) +{ + struct seq *seq = seq_create(); + while(!ovsrcu_barrier(seq, 1000)) { + /* do nothing */ + } + seq_destroy(seq); +} + static void destruct(struct ofproto *ofproto_, bool del) { @@ -1848,6 +1858,9 @@ destruct(struct ofproto *ofproto_, bool del) seq_destroy(ofproto->ams_seq); + /* wait for all the meter destroy work finished + */ + ofproto_rcu_barrier(); close_dpif_backer(ofproto->backer, del); }