Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp988725pxb; Wed, 6 Apr 2022 06:08:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwArC20LQsIbA8C8e3vskwD8msLZqrGjyeEaAaBVm4imx6Iu5HOc7jzXLjkt+S6BEiE26/j X-Received: by 2002:a17:902:b704:b0:156:624:934b with SMTP id d4-20020a170902b70400b001560624934bmr8799509pls.116.1649250486253; Wed, 06 Apr 2022 06:08:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649250486; cv=none; d=google.com; s=arc-20160816; b=gPFZ4grm2wLDhRSp/f11ZaPzsmD62UG6tln8WSmA3PDO4K47BH9a1fg0oAx/kjXbB8 Ccxk0yR7FP7queCW50JgajMspY/piXKk06e7cYI+XiXvoBnXVQjFdgEZFNnJy4PAsxxY HoEZLTqANK1X0nZOuwJqO6JijLi3jovqzzwp1rxVFd+ISvqSiH4tCW652M2JqxOQM9wy Q4HssEZksPNmOoH9rBu1JUN5DxzREPOj7vX6KBHG9nR1yJzduNm8Ns95Nojec75eB61N 3GtznZEm9Uc8f63v1qHa0IYIXWbkTVZ5tqIop6WiwtLQDO7n7CQMpFfzaSBj7iQniIbr 1cgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EggZ/J5GfHD9qCQejTWzcNvQhgLEhmjoSDTcXy9Kglc=; b=dHu6Tv9qaW2x1TxecGmajWa0l1xjsm5oFbUx26Q2q78SiZlELnIp/iPdfO+Q1r5jNS BgCCf4iYVYkDIdoj9IEb4TJK8NjdGMmmCILSRQ6hLML1IHajSN+PbB2hLjLVjdblvlpt T4iI4awTs8yk5DdVgQ1wib0GwSMU4MW27oIRTnuhWf9s4tj4QdTFRIqN+hJ7BPsVi1VV vzRbVVghg1DGVM0ZRve4duFX7Gy4mdsFvQZesvToPmQZ4AL0dVqK36qOk13iD/IRYyQL 9lccyUXProiGBUP4xeM6IITZ01HKPvd6QvcPK7bylgqISGuc87Fxi2xyrYM+omW98ztF bJNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="O0I/PHvA"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x189-20020a6363c6000000b003995a4ce0b9si5315490pgb.498.2022.04.06.06.08.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 06:08:06 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="O0I/PHvA"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 26F1E4754B4; Wed, 6 Apr 2022 03:30:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390583AbiDEWEA (ORCPT + 99 others); Tue, 5 Apr 2022 18:04:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349184AbiDEJtZ (ORCPT ); Tue, 5 Apr 2022 05:49:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3C31205D8; Tue, 5 Apr 2022 02:42:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 61090615E5; Tue, 5 Apr 2022 09:42:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 682FDC385A3; Tue, 5 Apr 2022 09:42:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151744; bh=WrBVVqM10/J6lxBsgTkDsZRT45DDOW82ezoBdJUPxIM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O0I/PHvAC7/4dIWHQCHsWx3Dz8KiYKuHxsQTrAK6OtZkvfkDlDZYJC9JblBlzgQLt NF1ICxm6uivZ5Uub9nTgsE5QhjWn4POOyFvqD2CaoLaGdr9Mzt+0tg+Ziw8Nr1e1XY 3biVHR+aR1JFLdEzyTosZ3oIRJsBx1yFNmvlsXpA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Cheng Li , Andrii Nakryiko , Sasha Levin Subject: [PATCH 5.15 525/913] libbpf: Unmap rings when umem deleted Date: Tue, 5 Apr 2022 09:26:27 +0200 Message-Id: <20220405070355.588417863@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: lic121 [ Upstream commit 9c6e6a80ee741adf6cb3cfd8eef7d1554f91fceb ] xsk_umem__create() does mmap for fill/comp rings, but xsk_umem__delete() doesn't do the unmap. This works fine for regular cases, because xsk_socket__delete() does unmap for the rings. But for the case that xsk_socket__create_shared() fails, umem rings are not unmapped. fill_save/comp_save are checked to determine if rings have already be unmapped by xsk. If fill_save and comp_save are NULL, it means that the rings have already been used by xsk. Then they are supposed to be unmapped by xsk_socket__delete(). Otherwise, xsk_umem__delete() does the unmap. Fixes: 2f6324a3937f ("libbpf: Support shared umems between queues and devices") Signed-off-by: Cheng Li Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20220301132623.GA19995@vscode.7~ Signed-off-by: Sasha Levin --- tools/lib/bpf/xsk.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c index e9b619aa0cdf..a27b3141463a 100644 --- a/tools/lib/bpf/xsk.c +++ b/tools/lib/bpf/xsk.c @@ -1210,12 +1210,23 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, int xsk_umem__delete(struct xsk_umem *umem) { + struct xdp_mmap_offsets off; + int err; + if (!umem) return 0; if (umem->refcount) return -EBUSY; + err = xsk_get_mmap_offsets(umem->fd, &off); + if (!err && umem->fill_save && umem->comp_save) { + munmap(umem->fill_save->ring - off.fr.desc, + off.fr.desc + umem->config.fill_size * sizeof(__u64)); + munmap(umem->comp_save->ring - off.cr.desc, + off.cr.desc + umem->config.comp_size * sizeof(__u64)); + } + close(umem->fd); free(umem); -- 2.34.1