From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 613CF1BF328 for ; Fri, 24 Jan 2025 17:13:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737738829; cv=none; b=SKdTJ960wrMbmWKX1Gjl4UNkCwdJEWyp03bs8FXsJ6rzLAe3iQXckPGkvVQzIDb95xKTQZztAqLhmE/820QnGC84rwjVEHXuDKwntGUQ+W1xBdEaNjB868eAG1PolgdweTJb/H9dXET+8aHwu5IpBxKugQjYTzoxm3FFUiodQVA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737738829; c=relaxed/simple; bh=iiMJlnjqVu9fqhSNV3EMXqwrwqj3JQEHc8FTUyKDyRs=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=kZFZIz9pSO4MzCSyAUlpLxJltgpmoal0dzy4G1RdESU7vS3t039uHM8zWwvFuxzJuQAaQe1hN1X7EYzhRnRV1eJVVO1ySlLgzqEAI+ZZ8a83NUeG+GM9iNa/N6mCxSqAt0h0St6+kTmUXgeL1CLF6Nqc2q4uchRLcx6U5OvGEg4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=htNmTDFO; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="htNmTDFO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737738826; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Bgl21DlUR8J6PmKG92PJjxElpV90g1dFpTjC8FMtbiQ=; b=htNmTDFOVL1qt7EltTsi7SxUvUYTBwnqAoQbNHeTkFCW6hIphDD00aMYFazzu8X+3+Shm3 b0gj+nM7sC1H1ZbNYanLHxL/Tc6MLXuRIBaNMOf/CKWjqxlL7kPH3B/CuuR6KHgUmAaN9Z FjvoHHL9iPOlmWqYJzcT+Imdb6dCErA= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-636-Mw3rn5klMlOohS_-NsEIug-1; Fri, 24 Jan 2025 12:13:45 -0500 X-MC-Unique: Mw3rn5klMlOohS_-NsEIug-1 X-Mimecast-MFC-AGG-ID: Mw3rn5klMlOohS_-NsEIug Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-ab367e406b3so238890066b.0 for ; Fri, 24 Jan 2025 09:13:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737738823; x=1738343623; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Bgl21DlUR8J6PmKG92PJjxElpV90g1dFpTjC8FMtbiQ=; b=Ab9MSBPOYcPHdiad7IinnKmeX6ogx1vjRnbm4LJOCzmrS8UkqlnqjwsqPygchPalMq ty0E40bNHtuXQWdmHabRbqUj2s+LvjciC8f12k/thU39xDA7iKvvXPGWDr5yaOnQOiXw Jhx4PCqrHY5BVtHjMqb0yXymDFwwsYnRBp7J9sDHZQQ6dXP5vFes6C7Cp6IYEGAkxzzk J2/S+OdNpTE6XKzk/PPl/kkOAtHHWlGT0AuskMqQnhJ9TZFe9/b/eJvOb9VkkwtTjfCV Zy4rDT0pBGA09bgooaVGiVRL+nvZHtrN00Kb4WxXtAiQwi22MXzvSaPzuJJmohQn+V86 rigA== X-Forwarded-Encrypted: i=1; AJvYcCUZql+3xb9Zpmwv3yXl+lavilWyNZGnGroM6bQwXd31Z5cgyoVD/qeyokLRyXoe4BA+K5puG42Wzo8Flg4=@vger.kernel.org X-Gm-Message-State: AOJu0YzZQP9HcNwhrVls4XWKQ3F2bhk71btyWKtF+Qi3HExvPgli/8bP 8I+RMrUJtIbHtyIGlUD/PQwN2EUjc5JFsEVb/bz6eScT4idoJU83IiiAk8PVsstSWFT4fhqGCyL JcO1mApK2WnSlGW8JbbQXK/M47IITVX14s9CLpH1tmd5FGPGO3yt+I8sZImsV3Q== X-Gm-Gg: ASbGncseOw7wWKRKtv+jdkJDdBuMF4wiCnMnD5ASmp0rjiObibdey2LO+dHD/Lu6a/a OrJQnFwpdMkjvrjzD1txAZACh7vHtqXbJ9IrkJSG/xvERzAamVktysY1VOxC2+caTfqBUvKgUfY fqQ9o1ViTY4n9/BpDYwzcHqYF1uJveC0RLLa8u1vrrjCVS/wKniDj3g+aUVf4JsAPe/yfiJPlC+ 2qdcDQ4MiPQxsE5BuUWwQdrzHPBnW4v/KDCMQUvnzA/4J/5Nqc62BrgwD/nSZ2p4wowgabSy/VR cvnZZotgCWBnHRcnJ8w= X-Received: by 2002:a17:906:4fcb:b0:aa6:90a8:f5ff with SMTP id a640c23a62f3a-ab38b3fbfe3mr3118161166b.50.1737738822876; Fri, 24 Jan 2025 09:13:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtqQo5YS3ajg4ppdOQhXWzuRmOA3oSoT7thyIDa4HsUOMGk7g+OCNkFH72qXuMXVWqyygG9w== X-Received: by 2002:a17:906:4fcb:b0:aa6:90a8:f5ff with SMTP id a640c23a62f3a-ab38b3fbfe3mr3118158166b.50.1737738822476; Fri, 24 Jan 2025 09:13:42 -0800 (PST) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab675e64d68sm159418166b.53.2025.01.24.09.13.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 09:13:41 -0800 (PST) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id DC576180AAB3; Fri, 24 Jan 2025 18:13:40 +0100 (CET) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Yunsheng Lin , Yunsheng Lin , davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com Cc: zhangkun09@huawei.com, liuyonglong@huawei.com, fanghaiqing@huawei.com, Alexander Lobakin , Xuan Zhuo , Jesper Dangaard Brouer , Ilias Apalodimas , Eric Dumazet , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net-next v7 2/8] page_pool: fix timing for checking and disabling napi_local In-Reply-To: <2aa84c61-6531-4f17-89e5-101f46ef00d0@huawei.com> References: <20250110130703.3814407-1-linyunsheng@huawei.com> <20250110130703.3814407-3-linyunsheng@huawei.com> <87sepqhe3n.fsf@toke.dk> <5059df11-a85b-4404-8c24-a9ccd76924f3@gmail.com> <87plkhn2x7.fsf@toke.dk> <2aa84c61-6531-4f17-89e5-101f46ef00d0@huawei.com> X-Clacks-Overhead: GNU Terry Pratchett Date: Fri, 24 Jan 2025 18:13:40 +0100 Message-ID: <8734h8qgmz.fsf@toke.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Yunsheng Lin writes: >> So I really don't see a way for this race to happen with correct usage >> of the page_pool and NAPI APIs, which means there's no reason to make >> the change you are proposing here. > > I looked at one driver setting pp->napi, it seems the bnxt driver doesn't > seems to call page_pool_disable_direct_recycling() when unloading, see > bnxt_half_close_nic(), page_pool_disable_direct_recycling() seems to be > only called for the new queue_mgmt API: > > /* rtnl_lock held, this call can only be made after a previous successful > * call to bnxt_half_open_nic(). > */ > void bnxt_half_close_nic(struct bnxt *bp) > { > bnxt_hwrm_resource_free(bp, false, true); > bnxt_del_napi(bp); *----call napi del and rcu sync----* > bnxt_free_skbs(bp); > bnxt_free_mem(bp, true); *------call page_pool_destroy()----* > clear_bit(BNXT_STATE_HALF_OPEN, &bp->state); > } > > Even if there is a page_pool_disable_direct_recycling() called between > bnxt_del_napi() and bnxt_free_mem(), the timing window still exist as > rcu sync need to be called after page_pool_disable_direct_recycling(), > it seems some refactor is needed for bnxt driver to reuse the rcu sync > from the NAPI API, in order to avoid calling the rcu sync for > page_pool_destroy(). Well, I would consider that usage buggy. A page pool object is created with a reference to the napi struct; so the page pool should also be destroyed (clearing its reference) before the napi memory is freed. I guess this is not really documented anywhere, but it's pretty standard practice to free objects in the opposite order of their creation. So no, I don't think this is something that should be fixed on the page pool side (and certainly not by adding another synchronize_rcu() call per queue!); rather, we should fix the drivers that get this wrong (and probably document the requirement a bit better). -Toke